From: "Mauricio Fernández" Date: 2005-11-07T09:46:06+09:00 Subject: Re: Lazy fun: Make unary minus silence stderr for backticks On Mon, Nov 07, 2005 at 08:33:35AM +0900, Sam Stephenson wrote: > The way I'm silencing stderr is a bit, um, agile. Can it be made to > work in Ruby on Windows without loading an external library (since > open3 doesn't work there)? 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 -- Mauricio Fernandez