From: Robert Klemme Date: 2010-01-21T17:27:17+09:00 Subject: Re: capture output in real time 2008/5/10 ara.t.howard : > > On May 9, 2008, at 6:08 PM, Paul Winward wrote: >> >> Note, I'm avoiding STDOUT.flush in sleep.rb since I won't be able to >> change the actual scripts I'll be passing to popen3. > > popen3 is going to be using fork/exec under the hood and should inherit the > sync setting of STDOUT, so try setting > >  STDOUT.sync = true > > before the popen and see if that helps - untested, but i'm running out the > door.... IMHO that can only work if you use fork with a block. Since Paul wants to start a new process that cannot possibly inherit buffering settings that way. Since Ruby decides buffering mode of stdout based on the type (i.e. if it is a terminal then sync = true otherwise not) and the child process cannot be influenced by Paul it follows that the only feasible way to use would be to present a tty as stdout to the child (via some form of pseudo tty mechanism). But that may have adverse effects because some programs change their output based on the type of stdout as well (just think about including colorization on ttys and omitting it on pipes). This is the place to ask: Paul, what do you need that behavior for? Maybe there are other mechanism to use. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/