Is there a simple, reliable way to tell when an IPC::Run
task has completed, i.e. any child process(es) have exited?
The docs are astonishingly silent on this.
It seems that looping on pumpable
works, though it's not really documented clearly as the right way to do things:
use strict;
use warnings;
use IPC::Run;
use 5.12.0;
my $handle = IPC::Run::start(['sleep', '10']);
while ($handle->pumpable)
{
sleep(0.5);
# do other stuff in the event loop
# so we don't want to block on finish
}
$handle->finish;
print("exited with '" . $handle->result . "'");
Is there a better option? finish
blocks, but then you can't do other work in your event loop while you wait for the proc to finish.
I'm surprised there isn't a simple
$handle->running
or
$handle->finished
Am I missing something obvious?
Similarly, there doesn't seem to be a documented way to get the pid of the child(ren).