perl – 关于IO :: Select的澄清

前端之家收集整理的这篇文章主要介绍了perl – 关于IO :: Select的澄清前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 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 "timeout\n";

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 ::选择或选择无关.)

猜你在找的Perl相关文章