How do I recover STDOUT in a signal handler during the code block execution?
Is there a way to know the 开发者_运维知识库previous value of a local
variable in signal handler?
{
open my $devnull, '>', '/dev/null';
local *STDOUT = $devnull;
...
}
Have a different filehandle dup'd from STDOUT before the local and use that in the signal handler.
It is possible to use select to save the old filehandle, like so:
{
open my $fh, '>', '/dev/null';
my $oldstdout = select($fh);
print $oldstdout "This prints to STDOUT";
print "Junk to /dev/null"
select $oldstdout;
print "Back to STDOUT";
}
精彩评论