my $cmdin=gensym; my $cmdout=gensym; my $cmderr=gensym; eval{ $pid = open3($cmdin, $cmdout, $cmderr, $cmd); #$val = waitpid(-1,0); }; die "Exception raised in block using open3: $@\n" if $@; $selector = IO::Select->new(); $selector->add($cmdout, $cmderr); #print "After selector->add\n"; while (@ready=$selector->can_read){ #print "In while loop\n"; foreach $fh (@ready) { #print "In foreach loop; fh is $$fh.\n"; my $byte; my @line; while ((sysread($fh, $byte, 1) == 1) && ($byte ne "\n")){push(@line,$byte);}; #$line = scalar <$fh>; #print "line we just read in is $line"; if (@line){ my $line2=join("",@line); #added here JWC 5/9/06 #print "Printing $line to log:\n"; #print "printing $$fh output to log\n"; if (fileno($fh) == fileno($cmderr)) {print LOG "STDERR: $line2\n";} else {print LOG "$line2\n";} #print "printed $$fh output to log\n"; } else{ #print "the line variable was empty--removing $$fh from selector.\n"; $selector->remove($fh); #print "removed $$fh from selector\n"; } #print "at end of foreach loop.\n"; } #print "at end of while loop.\n"; } close($cmdout)|| warn "Error: Could not close $$cmdout: $!"; close($cmderr)|| warn "Error: Could not close $$cmderr: $!"; print LOG "*-*-end_run-*-*\n"; close(LOG);