Created
August 12, 2014 16:53
-
-
Save plaster/616c7a95c739b0ad6099 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use utf8; | |
use strict; | |
use IO::File; | |
use IPC::Open2; | |
my $ofh = IO::File->new_tmpfile; | |
for (my $i = 1; $i < 20; ++$i) { | |
print $ofh ('x' x $i), "\n"; | |
} | |
printf STDERR "written to tmpfile\n"; | |
$ofh->seek(0, 0); | |
my $ifh = IO::Handle->new; | |
my $pid = open2($ifh, '<&' . $ofh->fileno, qw(cat -n)); | |
while (my $line = <$ifh>) { | |
printf STDERR "read: %s", $line; | |
} | |
$ifh->close; | |
$ofh->close; | |
waitpid($pid, 0); | |
exit(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% perl ipctest.pl | |
written to tmpfile | |
read: 1 x | |
read: 2 xx | |
read: 3 xxx | |
read: 4 xxxx | |
read: 5 xxxxx | |
read: 6 xxxxxx | |
read: 7 xxxxxxx | |
read: 8 xxxxxxxx | |
read: 9 xxxxxxxxx | |
read: 10 xxxxxxxxxx | |
read: 11 xxxxxxxxxxx | |
read: 12 xxxxxxxxxxxx | |
read: 13 xxxxxxxxxxxxx | |
read: 14 xxxxxxxxxxxxxx | |
read: 15 xxxxxxxxxxxxxxx | |
read: 16 xxxxxxxxxxxxxxxx | |
read: 17 xxxxxxxxxxxxxxxxx | |
read: 18 xxxxxxxxxxxxxxxxxx | |
read: 19 xxxxxxxxxxxxxxxxxxx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment