pipe = IO.popen("my_cmd 2>&0")
while ???
line = pipe.gets
puts line if some_condition
end
This is using Ruby 1.8.7 on Windows. my_cmd
is an application that prints database records to the stdout. One line per database record, and there's no way to know how many records there will be before I run the command. Each gets
call returns one record. Each gets
call could take a while, too. It's going over a network to a very large database, so the gets call won't be instant.
I'm processing the input just fine. The problem is, the loop never ends.
my_cmd
terminates when it reaches the end of the database. How does my Ruby script know when my_cmd
is done? What should ???
be in the code I posted above?