perlipc文档出错?

前端之家收集整理的这篇文章主要介绍了perlipc文档出错?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过我在 perlipc文档中看到的东西来解决问题.

If you’re writing to a pipe,you should also trap SIGPIPE. Otherwise,
think of what happens when you start up a pipe to a command that
doesn’t exist: the open() will in all likelihood succeed (it only
reflects the fork()’s success),but then your output will
fail–spectacularly. Perl can’t know whether the command worked
because your command is actually running in a separate process whose
exec() might have Failed. Therefore,while readers of bogus commands
return just a quick end of file,writers to bogus command will trigger
a signal they’d better be prepared to handle. Consider:

open(FH,"|bogus")  or die "can't fork: $!";
   print FH "bang\n"   or die "can't write: $!";
   close FH            or die "can't close: $!";

That won’t blow up until the close,and it will blow up with a
SIGPIPE. To catch it,you could use this:

$SIG{PIPE} = 'IGNORE';
   open(FH,"|bogus")  or die "can't fork: $!";
   print FH "bang\n"   or die "can't write: $!";
   close FH            or die "can't close: status=$?";

如果我正确地阅读它,它说第一个版本可能不会在最后关闭之前死掉.

但是,我的OS X盒子上没有发生这种情况(Perl版本5.8.9到5.15.9).无论我是否在那里有$SIG {PIPE}行,它都会打开“无法分叉:没有这样的文件或目录”.

我有什么误会?

解决方法

这是在5.6开发期间实现的更改,以便system()可以检测何时无法分叉/执行子项

https://github.com/mirrors/perl/commit/d5a9bfb0fc8643b1208bad4f15e3c88ef46b4160

它也在http://search.cpan.org/dist/perl/pod/perlopentut.pod#Pipe_Opens中记录

它本身指向perlipc,但perlipc确实似乎缺少这个

猜你在找的Perl相关文章