From: Sam Stephenson Date: 2005-11-07T10:11:36+09:00 Subject: Re: Lazy fun: Make unary minus silence stderr for backticks On 11/6/05, Mauricio Fern�ndez wrote: > batsman@tux-chan:/tmp$ cat test.rb > require 'rbconfig' > def nostderr > old = STDERR.dup > # unsure about the next line > file = (::Config::CONFIG["arch"] =~ /dos|win32|mingw/) ? "NUL" : "/dev/null" > STDERR.reopen(file) > STDERR.sync = true # you want this so `hello3` still outputs something below... > yield > ensure > STDERR.reopen(old) > end > > `hello` > nostderr { `hello2`; $stderr.puts "foo" } > `hello3` > batsman@tux-chan:/tmp$ ruby test.rb > test.rb:2: command not found: hello > test.rb:2: command not found: hello3 Interesting, I didn't know that reopening STDERR would affect subshells. It's more code but I think I prefer this approach. Sam