From: Robert Klemme Date: 2009-08-25T15:25:07+09:00 Subject: Re: Asynchronous process to process pipe IO On 24.08.2009 22:54, Pito Salas wrote: > Robert Klemme wrote: >> On 24.08.2009 22:16, Joel VanderWerf wrote: >>>> i = 0 >>>> >>>> >>> i = i+1 >>> end >>> else >>> exec("ruby -e '3.times {|i| p i; sleep 1}'") >>> end >>> end >>> >>> Does it work that way for you? >> Why are you guys using such a complex construction? If you just want to >> see the output when it comes why not just: >> >> system "./iacommand.rb" >> >> Or maybe this, if you need to process the output: >> >> IO.popen "./iacommand.rb" do |io| >> io.each_line do |line| >> puts line >> end >> end >> >> Note, you may have to do $stdout.sync = true in "iacommand.rb". >> >> Kind regards >> >> robert > > Robert, > > Thanks, the $stdout.sync = true was the magic bullet. > > Now, I am not exactly clear (reading the doc) about the difference > between exec and system... I do need to be able to send command line > arguments to iacommand.rb and I do indeed need to process the output 'as > it appears.' Then you'll want to use one of the popen family of functions. Even with IO.popen you can pass arguments: IO.popen ["./iacommand.rb", "arg", "arg"] do |io| ... end Note, if you also want to write to the process's stdin, you need to provide a file mode as second argument. See docs. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/