this worked for me but is kind of lame

stdout = ""
stderr = ""
process = Open4.background(cmd, 0=>"", 1=>stdout, 2=>stderr)

puts process.pid

while process.status do

  puts stdout unless stdout == ""
  puts stderr unless stderr == ""

  stdout.replace("")
  stderr.replace("")

  sleep 0.25
end

puts process.exitstatus



Daniel DeLorme wrote in post #567176:
> ara.t.howard wrote:
>> the general concepts are:
>>
>> IO.popen cmd, 'r+' do |pipe|
>>   pipe.sync = true ### you can do this once
>
> Except that doesn't work. If the subprocess doesn't flush its output,
> setting sync to true won't change anything. I tested with this:
>
> IO.popen("ruby -e '10.times{puts rand;sleep 1}'") do |pipe|
>    pipe.sync = true
>    while str = pipe.gets
>      puts str
>    end
> end
>
> and I get the output in one big block after 10 seconds. Does open3/open4
> change that? Somehow I doubt it.
>
> Daniel

-- 
Posted via http://www.ruby-forum.com/.