Hi,

@installedPackageList is an IO object, not an array.  You need to read
its contents, convert it into an array, and then remove things
(readlines does steps one and two at once):
@InstalledPackageList = @InstalledPackageList.readlines[5..-1]
daniel@daniel-desktop:~/lightconsolegem$ ri IO#readlines
----------------------------------------------------------- IO#readlines
     ios.readlines(sep_string=$/)  =>   array
------------------------------------------------------------------------
     Reads all of the lines in ios, and returns them in anArray. Lines
     are separated by the optional sep_string. If sep_string is nil,
     the rest of the stream is returned as a single record. The stream
     must be opened for reading or an IOError will be raised.

        f = File.new("testfile")
        f.readlines[0]   #=> "This is line one\n"


Dan


On Sun, Apr 13, 2008 at 6:29 PM, Jo Ay <wvs_chaos / gmx.de> wrote:
> Hi,
>  I'm new to Ruby, and so I was trying some stuff I was used to do with
>  ease in perl. Something like capturing and storing the output of a
>  commandline app in an array and manipulate that array afterwards.
>
>  After searching the net, I finally found the following solution (capture
>  output, then slice unecessary stuff away). Unfortunately slicing doesn't
>  work when i'm using open3 to capture the output. Question: what am I
>  doing wrong?
>
>  I attached the working code + the method I want to modify:
>
>  Regards
>  Joey
>
>
>  #############################################################
>
>  #!/usr/bin/ruby
>
>  class dpkg
>     def initialize
>         @InstalledPackageList = Array.new
>     end
>
>     def collect_inst_packages
>         @InstalledPackageList = `/usr/bin/dpkg -l`.split( /\n/ )
>         @InstalledPackageList.slice!(0, 5)
>     end
>
>     def get_inst_packages(filter = "")
>         @InstalledPackageList.grep(/#{filter}/)
>     end
>
>     def show_inst_packages(filter = "")
>         puts @InstalledPackageList.grep(/#{filter}/)
>     end
>  end
>
>  ax = dpkg.new
>  ax.collect_inst_packages
>  ax.show_inst_packages(ARGV[0])
>
>  #############################################################
>
>
>     # new method, that I want to use (but I also need to delete
>     # the first 5 lines of the dpkg output
>
>     def collect_inst_packages
>         require 'open3'
>         stdin, @InstalledPackageList, stderr =
>  Open3.popen3("/usr/bin/dpkg -l")
>         # cut away the first 5 lines
>     end
>
>  #############################################################
>  --
>  Posted via http://www.ruby-forum.com/.
>
>