开发者

Is there a way to know the previous value of a `local` variable in signal handler?

开发者 https://www.devze.com 2023-03-24 19:39 出处:网络
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?{

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";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消