开发者

IO.popen(my_cmd) - when is the subprocess done?

pipe = IO.popen("my_cmd 2>&0")
while ???
  line = pipe.gets
  puts line if some_condition
end

This is using Rub开发者_开发问答y 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?


Either

  while !out.eof?

or when you

 Process.wait pipe.pid

http://en.wikibooks.org/wiki/Ruby_Programming/Running_Multiple_Processes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜