use strict;
use warnings;
use POSIX
qw(:sys_wait_h
);
my $arg = "...";
my $pid;
my $reader;
my $r_bits = '';
if ($pid = open $reader, '-|'){ # ...
}
else {
exec('perl', 'foo.pl', $arg); die "cannot exec command"; }
while(1) {
my $wait_pid = waitpid $pid, WNOHANG
; if ($found && vec($rout, fileno($reader), 1)) { }
if ($wait_pid > 0) {
# ...
last;
}
...
}
dXNlIHN0cmljdDsKdXNlIHdhcm5pbmdzOwp1c2UgUE9TSVggcXcoOnN5c193YWl0X2gpOwoKbXkgJGFyZyA9ICIuLi4iOwpteSAkcGlkOwpteSAkcmVhZGVyOwpteSAkcl9iaXRzID0gJyc7CmlmICgkcGlkID0gb3BlbiAkcmVhZGVyLCAnLXwnKXsKCXZlYygkcl9iaXRzLCBmaWxlbm8oJHJlYWRlciksIDEpID0gMTsKCSMgLi4uCn0KZWxzZSB7CglkZWZpbmVkICRwaWQgb3IgZGllICJjYW5ub3Qgb3BlbiBwaXBlIjsKCWV4ZWMoJ3BlcmwnLCAnZm9vLnBsJywgJGFyZyk7CglkaWUgImNhbm5vdCBleGVjIGNvbW1hbmQiOwp9Cgp3aGlsZSgxKSB7CglteSAkd2FpdF9waWQgPSB3YWl0cGlkICRwaWQsIFdOT0hBTkc7CglteSAkZm91bmQgPSBzZWxlY3QobXkgJHJvdXQgPSAkcl9iaXRzLCB1bmRlZiwgdW5kZWYsIDApOwoJaWYgKCRmb3VuZCAmJiB2ZWMoJHJvdXQsIGZpbGVubygkcmVhZGVyKSwgMSkpIHsKCQlwcmludCBkb3sgbG9jYWwgJC87IHJlYWRsaW5lKCRyZWFkZXIpIH07Cgl9CglpZiAoJHdhaXRfcGlkID4gMCkgewoJCSMgLi4uCgkJbGFzdDsKCX0KCgkuLi4KfQ==