use IPC::Open3; use IO::Select; $cmd="find /fst/home/ -name '*ooo*'"; $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd); close(CMD_IN); $SIG{CHLD} = sub { print "REAPER: status $? on $pid\n" if waitpid($pid, 0) > 0 }; $selector = IO::Select->new(); $selector->add(*CMD_ERR, *CMD_OUT); while (@ready = $selector->can_read) { foreach $fh (@ready) { $line = scalar <$fh>; if (fileno($fh) == fileno(CMD_ERR)) {print "STDERR: ", $line} else {print "STDOUT: ", $line} ($line) || $selector->remove($fh); } } close(CMD_OUT); close(CMD_ERR);