On Tue, Apr 23, 2013 at 11:06 AM, fox foxmaster <lists / ruby-forum.com>wrote:

> That was a sweet bit of code, I have scripted some in bash and thats
> maybe why the looks like it does :) .
>
> But I have applied the "ruby" style to the code as you suggested and it
> works good for this part:
> cmd.each do |c|
>   command1 = IO.popen(["plink.exe", "-P", port.to_s, "-pw", pw,
> "#{user}@#{ip}", c]) {|io| io.each {|line|}}
> end
>
> so beautiful simple.
>
> but when I get to the part where I want to download the files I get
> stuck:
> output.each do |f|
>   download = IO.popen(["pscp.exe", "-P", port.to_s, "-pw", pw,
> "#{user}@#{ip}:f"]) {|io| io.each {|line|}}
>   puts f
>   puts download
> end
>
> I have modified it a bit to see what values I have in the variables, but
> the output is abit strange:
> If1.cap
> #<IO:0x2845d70>
> If2.cap
> #<IO:0x28456f8>
>
> I store output in a array, so I wounder is a array item always
> surrounded by [item]? Is it possible to show the download in another
> format not IO:0x..... more like the actual command?
>

Well, you can use

{|io| io.read}

instead of

{|io| io.each {|line|}}

but that will only give you the output from pscp.  And apparently that
contains [] because it's an error message.  You probably want to look at
the other variants of popen to properly evaluate the result code of the
external command and react appropriately.
http://rdoc.info/stdlib/open3/1.9.3/Open3#popen3-class_method

Cheers

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/