I am using IO::Select
.
I didn't expect this code to terminate only when I manually kill the forked process. Is this correct behavior?
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";
From 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}
.
So closing the file handle in $ph
(which is done when $ph
goes out of scope) waits for the child to complete.
(This has nothing to do with IO::Select or select
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With