From: Eric Hodel Date: 2006-12-01T16:10:52+09:00 Subject: Re: Ruby equivalent to "exec > $logfile 2>&1" in sh script? On Nov 30, 2006, at 19:24 , El Gato wrote: > Phil Rhoades wrote: >> I quite frequently have something like: >> >> exec > $logfile 2>&1 >> >> at the top of my shell scripts to output everything that follows >> (including errors) into a log file - is there some way of doing >> the equivalent in a Ruby script? > > This seems to work: > > outfile = File.open("output.txt", "w") > $stdout.reopen outfile > $stderr.reopen outfile > > puts "hello world!" > system("dir no_exist") Not really. $ ruby outfile = File.open("output.txt", "w") $stdout.reopen outfile $stderr.reopen outfile 0.upto 10 do |v| (v%2==0 ? STDOUT : STDERR).puts v; end $ cat output.txt 1 3 5 7 9 0 2 4 6 8 10 -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!