Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created November 16, 2012 00:13
Show Gist options
  • Save Shinpeim/4082651 to your computer and use it in GitHub Desktop.
Save Shinpeim/4082651 to your computer and use it in GitHub Desktop.
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