From: Brian Candler Date: 2007-04-06T16:21:59+09:00 Subject: Re: A convoluted question about stdout On Fri, Apr 06, 2007 at 03:29:12PM +0900, Sonny Chee wrote: > I know I can do a $stdout.reopen and redirect it to a file. Note that STDOUT is tied to the underlying operating system's concept of "standard output" - for Unix this is the open file on file descriptor 1. So if you *reopen* $stdout (or STDOUT) you'll change what fd 1 points at. Then, anything else which writes directly to fd 1 - e.g. C extensions, or external programs run using system() or exec() - will also write to this file. Now, you can change the global variable $stdout to point to a different IO object. In that case, anything in Ruby which does "$stdout.puts" will write to that new object. But anything which writes directly to fd 1 will still be writing to whatever the OS has attached to fd 1. Regards, Brian.