From: Eric Hodel Date: 2007-10-13T00:14:49+09:00 Subject: Re: Ignore printout On Oct 11, 2007, at 22:45 , Fredrik wrote: >> You will need to reopen STDOUT to /dev/null > > Then I have two more questions to that :) > > 1) What's the difference between $stdout and STDOUT? They seem to be > the same thing. http://blog.segment7.net/articles/2006/08/17/stdout-vs-stdout In your case you want to reopen STDOUT because somebody using your code may have changed $stdout, if they want to capture or redirect output. > 2) In my pickaxe book I read that "Assignment to $stdout is > depracated; use $stdout.reopen instead." But if I want to redirect > $stdout and then $direct it back to what it was before, surely I HAVE > to use assignment to $stdout. Like this: I don't think this is true anymore. You can't reopen using StringIO to capture regular ruby puts or p. > out = $stdout > $stdout = File.new('/dev/null','w') > puts 'This is not to be seen by anybody.' > $stdout.reopen(out) > > If I use reopen on the second line instead, the 'out' variable comes > along to this new value and nobody knows where the "usual stdout" is, > right? Right, you should dup $stdout there. -- Poor workers blame their tools. Good workers build better tools. The best workers get their tools to do the work for them. -- Syndicate Wars