From: Rob Biedenharn Date: 2008-05-31T22:35:04+09:00 Subject: Re: getting standard error and output from ruby script in real time On May 31, 2008, at 8:50 AM, Stefano Crocco wrote: > On Friday 30 May 2008, Dave Bass wrote: >> Stefano Crocco wrote: >>> of KDE. I'd be glad if someone could give >>> me a hint on this, so that at least >>> I can know whether I have to look for >>> documentation about ruby or about >>> KDE. >> >> It's to do with buffering. Buffering takes place within Ruby (I >> think) >> but also in the operating system. Stderr is usually unbuffered >> whereas >> stdout is usually buffered. I.e. the output is accumulated in a >> memory >> buffer until it reaches a certain size, then the block is flushed >> to the >> output stream. This is a lot more efficient that outputting it >> character-by-character to the output device. >> >> In my experience (various languages and OSes), buffering can cause >> problems that are difficult or impossible to resolve. > > Thanks for the information. I think I'll look at the source code of > some tool > which does what I want and see how it works. > > Stefano $stdout.sync = true; $stdout.flush The #sync setting of true means "unbuffered" (sync'd to the destination every time). If you build up messages, you can call #flush on the IO yourself instead. print "hello " print "world" puts "!" STDOUT.flush -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com