From: El Gato Date: 2006-12-01T12:24:56+09:00 Subject: Re: Ruby equivalent to "exec > $logfile 2>&1" in sh script? Phil Rhoades wrote: > People, > > 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? > > Thanks, > > Phil. This seems to work: outfile = File.open("output.txt", "w") $stdout.reopen outfile $stderr.reopen outfile puts "hello world!" system("dir no_exist") === output.txt === hello world! Volume in drive C has no label. Volume Serial Number is 7874-56C8 Directory of C:\ File Not Found -- Posted via http://www.ruby-forum.com/.