my $pid; eval{ $pid = open3($infh, $outfh, $errfh, $cmd); }; die "open3: $@\n" if $@; print "PID was $pid\n"; my $sel = new IO::Select; # create a select object to notify # us on reads on our FHs $sel->add($outfh,$errfh); # add the FHs we're interested in while(my @ready = $sel->can_read) { # read ready foreach my $fh (@ready) { my $line = <$fh>; # read one line from this fh if(not defined $line){ # EOF on this FH $sel->remove($fh); # remove it from the list next; # and go handle the next FH } if($fh == $outfh) { # if we read from the outfh print OUTPUT $line; # print it to OUTFH } elsif($fh == $errfh) {# do the same for errfh print ERRLOG $line; } else { # we read from something else?!?! die "Shouldn't be here\n"; } } }