| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
## Submitted by Blair Zajac <[email protected]> |
| 4 |
|
| 5 |
## Tests blocking when piping though a &sub coprocess. |
| 6 |
## Fixed, now in test suite. |
| 7 |
|
| 8 |
$| = 1; |
| 9 |
|
| 10 |
use strict; |
| 11 |
use Carp; |
| 12 |
use Symbol; |
| 13 |
use IPC::Run 0.44 qw(start); |
| 14 |
|
| 15 |
print "My pid is $$\n"; |
| 16 |
|
| 17 |
my $out_fd = gensym; |
| 18 |
open( $out_fd, ">ZZZ.test" ) |
| 19 |
or die "$0: open: $!\n"; |
| 20 |
|
| 21 |
my $queue = ''; |
| 22 |
|
| 23 |
my @commands = ( |
| 24 |
[ [ 'cat', '-' ], \$queue, '|' ], |
| 25 |
[ ['cat'], '|' ], |
| 26 |
[ \&double, '>', $out_fd ] |
| 27 |
); |
| 28 |
|
| 29 |
my $harness = start 'debug' => 10, map { @$_ } @commands; |
| 30 |
$harness |
| 31 |
or die "$0: harness\n"; |
| 32 |
|
| 33 |
close($out_fd) |
| 34 |
or die "$0: cannot close: $!\n"; |
| 35 |
|
| 36 |
for ( 1 .. 100 ) { |
| 37 |
$queue .= rand(100) . "\n"; |
| 38 |
$harness->pump; |
| 39 |
} |
| 40 |
$harness->finish |
| 41 |
or die "$0: finish\n"; |
| 42 |
|
| 43 |
exit 0; |
| 44 |
|
| 45 |
sub double { |
| 46 |
while (<STDIN>) { |
| 47 |
s/\s+$//; |
| 48 |
print "$_ $_\n"; |
| 49 |
} |
| 50 |
} |