From: Robert Klemme Date: 2012-05-22T20:58:00+09:00 Subject: Re: spawn a process and keep the output, but stdout -> $stdout On Tue, May 22, 2012 at 7:12 AM, David Madison wrote: > open("|cmd"..) is the simplest, but if you want a simple way to examine > the output you can use popen and a thread: > > bc = IO.popen('bc','r+') I'd rather use the block form - as always. > # A thread which just reads output from bc and prints it > bcout = Thread.new { >  while !bc.eof >    puts "BC says: #{bc.gets}" >  end > } Or simply bcout = Thread.new { bc.each {|line| puts line} } or even simpler on 1.9 bcout = Thread.new { IO.copy_stream(bc, $stdout) } Note, this will likely not get line wise output. > # Now let's control bc: > > bc.puts "3*2" > bc.puts "4*8" > > sleep 2 > bc.puts "41958/999" > > # Remember we need to send a quit so that the process ends! > bc.puts "quit" bc.close_write works as well. > # Make sure to wait for the bcout read loop to finish before we exit > bcout.join Right. There are a whole lot of interesting methods in Open3 as well: http://rdoc.info/stdlib/open3/Open3 Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/