From: Robert Klemme Date: 2009-12-11T19:35:29+09:00 Subject: Re: Redirecting standard output 2009/12/11 Robert Gleeson : > Omar Campos wrote: >> Thanks, that's exactly what I was looking for!  Nice gem by the way.  I >> tried to "gem install" it, but I got a weird error message, don't >> remember what it was. > > No need for a gem. The gem was not needed for the redirection functionality but for getting at information about the method. > $stdout = File.new '/path/to/file', 'w' > puts 'foobar' > $stdout = STDOUT > puts 'foobar' This does only work for redirections of output for the particular process. It will fail in these cases - sub processes started - all entities which remembered $stdout instance (e.g. a logger) Your last solution is better (although you do not necessarily need a constant for that). Btw, apparently you don't even need the mode - that is inherited from the original. So you can do: $ ruby19 -e '$stderr.reopen("log"); $stderr.puts("foo")' ; cat log foo $ ruby19 -e '$stdin.reopen("log"); p gets' "foo\n" $ Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/