From: Reimer Behrends Date: 2003-11-26T09:37:11+09:00 Subject: Re: redirect stdout Mark J. Reed (markjreed@mail.com) wrote: [...] > But it also loses the original STDOUT, and M Onoma did say that the > redirection was to be temporary. Good catch. I missed that one. > 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) You need old_stdout.close here. Otherwise you have a file descriptor leak. Similarly: > 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.close > $stdout = STDOUT (And, of course, add the "w" flag to the open call, as you had already mentioned.) Reimer Behrends