From: Park Heesob Date: 2002-07-10T13:48:34+09:00 Subject: Re: Redirecting standard error "Gilles Filippini" wrote in message news:3D298A0E.35ECAE66@free.fr... > Hi, > > I saw many examples about how to redirect standard output to - say - a > string buffer. > What about standard error? Has anybody already done this? > > _gilles. Hi, You can redirect standard error to file like this: def redir(redout, rederr) raise unless block_given? oldout, olddef, olderr = $stdout.dup, $defout.dup, $stderr.dup begin f1 = File.open(redout,'w+') f2 = File.open(rederr,'w+') $stdout = f1.dup $defout = f1.dup $stderr = f2.dup yield ensure f1.close f2.close $stdout = oldout $defout = olddef $stderr = olderr end end redir("/tmp/stdout", "/tmp/stderr") do puts "hello, world!" `ls notexist` end Park Heesob