sub reader_thread { my ($hr,$who) = @_; my $c; my $h; my $r; my $q; threads->detach(); # determine handle. if( $who eq 'o' ){ $h = $hr->{'stdout'}; } else { $h = $hr->{'stderr'}; } # Get the output queue $q = $hr->{'Q'}; while( 1 ){ if( $hr->{'alive'} == 0 ){ last; } # Try to read *ONE* byte $r = read( $h, $c, 1 ); if( $r > 0 ){ if( length($c) ){ $q->enqueue($c); } } else { threads->yield(); } } }