I'm working on a script that uses IO.popen to open another program and continually read the data. It's like this:
process = IO.popen(["/the/program", "argument", "argument"])
loop do
line = process.gets
puts "#{line}"
end
(The actual program does more than just printing the output, obviously - that's just an example.)
The issue I'm running into is that popen seems to be buffering STDOUT from the opened process. I've confirmed this by running the program directly from a shell and through popen, side-by-side, and the Ruby one never gets one line at a time. It always gets multiple lines at a time, and is delayed.
I've tried
STDOUT.sync = true
... before popen, but that hasn't changed anything.
The program in question is definitely using \n as a new line, so that's not the issue.