R
Ronny
I try to use the program below to catch standard output and standard
error
of a process. The program itself runs well, and it *does* write at
least to
standard output, but in the code below, the line saying "### READING"
is never printed and @msg is still empty afterwards. This means that
$selector->can_read() must have returned false already the first time
it was called. Any suggestion on what could I have done wrong here?
my @msg;
my $pid=open3(*CMD_IN,*CMD_OUT,*CMD_ERR,@cmd)
or confess "Open3 error: $!\n";;
$SIG{CHLD} = sub {
waitpid($pid,0)>0 &&
print "SIGCHILD status=$? pid=$pid\n";
};
my $selector=IO::Select->new();
$selector->add(*CMD_ERR,*CMD_OUT);
while(my @ready=$selector->can_read()) {
foreach my $fh (@ready) {
print "### READING\n";
push @msg,scalar(<$fh>);
$selector->remove($fh) if eof($fh);
}
}
close CMD_OUT;
close CMD_ERR;
error
of a process. The program itself runs well, and it *does* write at
least to
standard output, but in the code below, the line saying "### READING"
is never printed and @msg is still empty afterwards. This means that
$selector->can_read() must have returned false already the first time
it was called. Any suggestion on what could I have done wrong here?
my @msg;
my $pid=open3(*CMD_IN,*CMD_OUT,*CMD_ERR,@cmd)
or confess "Open3 error: $!\n";;
$SIG{CHLD} = sub {
waitpid($pid,0)>0 &&
print "SIGCHILD status=$? pid=$pid\n";
};
my $selector=IO::Select->new();
$selector->add(*CMD_ERR,*CMD_OUT);
while(my @ready=$selector->can_read()) {
foreach my $fh (@ready) {
print "### READING\n";
push @msg,scalar(<$fh>);
$selector->remove($fh) if eof($fh);
}
}
close CMD_OUT;
close CMD_ERR;