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

perl – 关于IO :: Select的澄清

发布时间:2020-12-16 06:19:32 所属栏目:大数据 来源:网络整理
导读:我正在使用 IO::Select . 我没想到只有当我手动终止分叉进程时才会终止此代码.这是正确的行为吗? use strict;use warnings;STDOUT-autoflush();use IO::Select;open(my $ph,"-|","perl -e 'sleep 1 while 1'");my $sel = IO::Select-new();$sel-add($ph);$s
我正在使用 IO::Select.

我没想到只有当我手动终止分叉进程时才会终止此代码.这是正确的行为吗?

use strict;
use warnings;

STDOUT->autoflush();

use IO::Select;

open(my $ph,"-|","perl -e 'sleep 1 while 1'");

my $sel = IO::Select->new();

$sel->add($ph);

$sel->can_read(2) or warn "timeoutn";

print "woohoo?n";

解决方法

open,

Closing any piped filehandle causes the parent process to wait for the child to finish,then returns the status value in $? and ${^CHILD_ERROR_NATIVE}.

因此关闭$ph中的文件句柄(当$ph超出范围时完成)等待孩子完成.

(这与IO ::选择或选择无关.)

(编辑:李大同)

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

    推荐文章
      热点阅读