From: ts Date: 2001-01-13T02:34:30+09:00 Subject: [ruby-talk:9213] Re: redirecting stdout --- dup2 >>>>> "R" == Raja S writes: Something like this ? ( but there is problem with flush) R> class File R> def File.with_output_to_file (fname, mode="w", &blk) R> begin R> dout = $defout stdout = $stdout.dup stderr = $stderr.dup R> $defout = File.open fname, mode $stdout.reopen($defout) $stderr.reopen($defout) R> yield R> ensure R> $defout.close $stdout.reopen(stdout) $stderr.reopen(stderr) R> $defout = dout R> end R> end R> end Guy Decoux