加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perlipc文档出错?

发布时间:2020-12-15 23:34:39 所属栏目:大数据 来源:网络整理
导读:我试图通过我在 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 succ
我试图通过我在 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 "bangn"   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 "bangn"   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确实似乎缺少这个

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读