Assuming a handle created with the following code:
use IO::File;
my $fh = IO::File->new;
my $pid = $fh->open('some_long_running_proc |') or die $!;
$fh->autoflush(1);
$fh->blocking(0);
and then read with a loop like this:
while (some_condition_here) {
my @lines = $fh->getlines;
...
sleep 1;
}
What do I put as some_condition_here, which will return false if the process at the other end of the channel is completed?
Testing for $fh->eofwill not work, as the process can still work without printing any new lines. Testing for $fh->openedseems nothing helps.
I am currently using $pid =! waitpid($pid, WNOHANG)one that seems to work in a POSIX compatible environment. Is this the best way? What's on Windows?
source
share