Created
November 16, 2012 00:13
-
-
Save Shinpeim/4082651 to your computer and use it in GitHub Desktop.
This file contains 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 strict; | |
use warnings; | |
use utf8; | |
use IO::Tee; | |
use IPC::Open3; | |
use autodie; | |
my $cmd = q!perl -e 'while(1){print ++$i."\n"}'!; | |
my ($out); | |
my $pid = open3(undef, $out, ">&=".fileno(\*STDERR), $cmd); #srderrは親のstderrにリダイレクト | |
my $out_tee = IO::Tee->new($out,\*STDOUT); # stdoutはteeして親のstdoutにも流す | |
while (defined(my $line = <$out_tee>)) { | |
#子の標準出力を監視してなんかする | |
if ($line =~ /1000/) { | |
kill 'INT', $pid; | |
last; | |
} | |
} | |
$out->close; | |
waitpid($pid,0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment