T
T. Onoma
I need to temporarily redirect standard output to nowhere. Not sure how to do.
Suggestions?
Thanks,
-t0
Suggestions?
Thanks,
-t0
T. Onoma ([email protected]) said:I need to temporarily redirect standard output to nowhere. Not sure
how to do.
Minor correction: forgot the mode on my open calls.
Add , "w" to both of the below:
STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null", "w" )
$stdout = File.open( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null", "w" )
-Mark
Mark J. Reed said:Or, if you aren't invoking any processes external to ruby, you can leave
STDOUT alone and just change $stdout:
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.close
$stdout = STDOUT
Minor correction: forgot the mode on my open calls.
Add , "w" to both of the below:
STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null", "w" )
$stdout = File.open( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null", "w" )
-Mark
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.