my $writer = IO::Pipe->new();
$writer->writer();
print $writer $some_function();
$writer->flush();
$writer->close;
如果some_function
产生某些异常或STDERR,会发生什么?是否写入$writer
?如果没有,怎么能做到?
答案 0 :(得分:0)
您需要抓住$SIG{__WARN__}
和/或$SIG{__DIE__}
{
my $writer = IO::Pipe->new();
$writer->writer();
local $SIG{__WARN__} = sub { print $writer $_[0] };
local $SIG{__DIE__} = sub { print $writer $_[0] };
print $writer $some_function();
$writer->flush();
$writer->close;
}
$SIG{__DIE__}
处理程序需要进行修改,具体取决于您要如何处理严重错误。