Hi Rubists
I’m still learning Ruby, and I have a small question.
Is there a way to read the output of a program “line by line”, in
real-time ?
I would like to execute CVSup and to display its output in a Gtk
list-view component each time CVSup prints a line on $stdout.
I have experimented 3 tests: each one prints directly the output in one
shot (this is not what I want) :
···
TEST 1
IO.popen("./plok") { |pipe|
pipe.each_line { |line|
puts line
}
}
TEST 2
rd, wr = IO.pipe
fork {
puts “child”
$stdout = wr
rd.close
exec("./plok")
}
wr.close
puts "father = waiting for output"
while rd.gets do
puts "==> #{$_}"
end
TEST 3
IO.popen("./plok") { |ruby|
while ruby.gets do
puts("==> #{$_}")
end
}
Thank you in advance (and excuse-me for my bad english),
–
Laurent