On Thu, Jun 28, 2012 at 4:36 PM, Andrea Dallera <[email protected]> wrote: > This is far from a clean solution, mind you:
Things to improve:
- use the block form of IO.popen
- close writing when finished
- join on the reader thread
> pipe = IO.popen("command", "options")
> Thread.new do
> while(true)
> p pipe.gets
> end
> end
> pipe.puts("I'm writing this on the pipe")
>
> You should see the process's output in your STDOUT.
$ ruby19 popen.rb
0.000 main : "started"
0.040 writer : "about to write first line"
0.041 reader : " 1\tfirst line\n"
1.041 writer : "about to write second line"
1.041 reader : " 2\tsecond line\n"
6.041 writer : "about to write last line"
6.041 reader : " 3\tlast line\n"
6.041 writer : "closed"
6.041 writer : "joined"
6.042 main : "finished"
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
popen.rb
Description: Binary data
