From: Lloyd Zusman Date: 2007-02-15T19:38:34+09:00 Subject: Re: Another Programming Ruby Question Bharat Ruparel writes: > That set me thinking what does the line: > $stderr.sync = $stdout.sync = true > actually do? (from the "sync= (IO)" section of http://www.ruby-doc.org/core/): ios.sync = boolean => boolean Sets the ``sync mode'' to true or false. When sync mode is true, all output is immediately flushed to the underlying operating system and is not buffered internally. Returns the new state. See also IO#fsync. f = File.new("testfile") f.sync = true (produces no output) When data is output through an IO handle, it might be buffered. What this means is that the data is held until a certain number of bytes are received or until certain characters are fed to the stream (such as newline), and only then are they sent to the output destination. The "sync mode" determines whether this buffering takes place ... if it's set to true, then there is no such buffering, and the data is "synchronized" with the output destination immediately upon being sent through the IO handle. The statement you refer to above makes sure that $stdout and $stderr are both synchronized. Therefore, in the thread, data written to these handles will be output immediately. Without your statement, there could be a delay between the moment that the data is sent to $stdout or $stderr and it shows up on the terminal. That's why you are seeing the output in a different sequence, depending on whether or not the sync mode is set. As you can see, this has nothing to do with setting $stdout and $stderr to be in sync with each other. -- Lloyd Zusman ljz@asfast.com God bless you.