Skip to content

Instantly share code, notes, and snippets.

@caseydentinger
Created April 3, 2017 20:02
Show Gist options
  • Save caseydentinger/7611eb0acb05e001b5f6cf02ecf984e1 to your computer and use it in GitHub Desktop.
Save caseydentinger/7611eb0acb05e001b5f6cf02ecf984e1 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use IPC::Open3;
use IO::Select;
my $child_pid = open3(*W, *R, *E, "/usr/bin/yes");
close (W);
my ($selector) = IO::Select->new();
$selector->add (*R, *E);
my $l = 0;
while (1) {
last if scalar ($selector->handles) == 0;
my @ready = $selector->can_read (1);
for my $fh (@ready) {
my $ffh = fileno($fh);
if (eof ($fh)) {
$selector->remove ($fh);
next;
}
my $line = scalar <$fh>;
chomp $line;
$l++;
if ($ffh == fileno(R)) {
} elsif ($ffh == fileno (E)) {
}
print "$l\n" if $l =~ /00000$/;
}
}
close(R);
close(E);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment