# cmd3sel - control all three of kids in, out, and error. use IPC::Open3; use IO::Select; my $cmd = "grep vt33 /none/such - /etc/termcap"; my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd); $SIG{CHLD} = sub { warn "REAPER: status $? on $pid\n" if waitpid($pid, 0) > 0 }; print CMD_IN "This line has a vt33 lurking in it\n"; close(CMD_IN); my $selector = IO::Select->new(); $selector->add(*CMD_ERR, *CMD_OUT); while (my @ready = $selector->can_read) { foreach my $fh (@ready) { if (fileno($fh) == fileno(CMD_ERR)) {print "STDERR: ", scalar } else {print "STDOUT: ", scalar } $selector->remove($fh) if eof($fh); } } close(CMD_OUT); close(CMD_ERR);