ruby - Blocking Call In Popen -
pipe = io.popen('./myblockingprogram') while line = pipe.gets puts "hello world" end
where myblockingprogram
program blocks until receives data on network, , prints text stdout. tested running bash directly works great.
however, when run program above, never see "hello world" lines printed stdout (the console). wrong popen starts whole new process... , therefore though makes blocking call should not prevent main ruby program running due global interpreter lock?
is there better way structure program this, want read text lines output program , process results in way (there no terminating condition, may run forever)?
make sure myblockingprogram flushes output buffer when writes stdout.
a simple example myblockingprogram is:
#!/bin/ruby 100.times sleep 10 $stdout.puts "hello world" $stdout.flush end
without flush command don't see result pipe until subprocess finishes. flush command, see intermediate results subprocess.
Comments
Post a Comment