# preserve STDOUT
open $oldSTDOUT, ">&STDOUT" || warn "Can't preserve STDOUT\n$!\n";
+
close STDOUT;
# preserve STDERR
open (OLDER, ">&", \*STDERR) || warn "Can't preserve STDERR\n$!\n"
+;
close STDERR;
# if you want to capture any messages in the meantime, point STDER
+R to a memory location
open (STDERR, ">", \$err) || warn "Can't redirect STDERR\n$!\n";
# restore STDERR
open (STDERR, ">&", \*OLDER) || warn "Can't restore STDERR\n$!\n";
close OLDER;
# restore STDOUT
open STDOUT, ">&", $oldSTDOUT;
# you may want to flush buffers at some point
select STDERR; $| = 1;
select STDOUT; $| = 1;
|