+------------------------+----------------------+ | Parent | Child | +------------------------+----------------------+ | - open3(...); | | | - | - ... | | | - Waits for child to | - print STDERR 1027; | | | write to STDOUT or | - print STDERR 1028; | | | for child to end. | - print STDERR 1029; | T | | - print STDERR 1030; | i | | - print STDERR 1031; | m | | - Pipe full. | e | | Waits for parent | | | | to empty it. | | | | | v | Still waiting... | Still waiting... | +------------------------+----------------------+ #### my %lookup = ( \*OUT => [ \*OUT, 'STDOUT', '' ], \*ERR => [ \*ERR, 'STDERR', '' ], ); MAIN_LOOP: for (;;) { my @r = $r_sel->can_read(); foreach my $fh (@r) { last MAIN_LOOP if eof($fh); my $buf_ptr = $lookup{$fh}[2]; 1 while read($fh, $$buf_ptr, $BLOCK_SIZE, length($$buf_ptr)); print("$lookup{$fh}[1]: $1") while $$buf_ptr =~ s/^(.*\n)//; } } foreach my $fh (keys %lookup) { print("$lookup{$fh}[1]: $lookup{$fh}[2]\n") if length $lookup{$fh}[2]; }