From: "Mark J. Reed" Date: 2003-11-25T01:42:10+09:00 Subject: Re: redirect stdout On Mon, Nov 24, 2003 at 03:49:21PM +0000, Reimer Behrends wrote: > T. Onoma (transami@runbox.com) wrote: > > I need to temporarily redirect standard output to nowhere. Not sure > > how to do. > > Assuming you run some *IX: > > STDOUT.reopen "/dev/null", "w" > > will redirect the standard output (including not just Ruby output, > but even the output of subprocesses) to /dev/null. But it also loses the original STDOUT, and M Onoma did say that the redirection was to be temporary. You can accomplish that by saving the original value and restoring it later, like this: old_stdout = STDOUT.dup STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" ) . . . STDOUT.reopen(old_stdout) Or, if you aren't invoking any processes external to ruby, you can leave STDOUT alone and just change $stdout: $stdout = File.open( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" ) . . . $stdout = STDOUT -Mark