Skip to content

Instantly share code, notes, and snippets.

@horgh
Created March 27, 2018 03:07
Show Gist options
  • Save horgh/82cfdbcfac9f3c082257d2f3ad770277 to your computer and use it in GitHub Desktop.
Save horgh/82cfdbcfac9f3c082257d2f3ad770277 to your computer and use it in GitHub Desktop.
IPC::Run PR#99 test code
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Handle ();
my $fh = IO::Handle->new_from_fd(3, '+<') or die "new_from_fd(): $!";
$fh->autoflush(1);
my $i = 0;
while (1) {
print { $fh } "$i\n";
$i++;
sleep 1;
}
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper qw( Dumper );
use IPC::Run ();
#my $magic_fh;
#open($magic_fh, '>&STDOUT') or die "dup stdout $!";
my $wanted_fh;
open($wanted_fh, '+<', '/tmp/blah.dat') or die "open(): $!";
my $printer = sub {
if (ref $_) {
print "child: " . Dumper($_) . "\n";
return;
}
print "child: $_";
};
my $stdout = sub { $printer->(@_) };
my $stderr = sub { $printer->(@_) };
my @command = './test-ipc-run-child.pl';
my $harness = IPC::Run::start(
\@command,
\undef,
$stdout,
$stderr,
$wanted_fh,
);
if ( !$harness ) {
die 'error starting process';
}
while (1) {
print ".\n";
$harness->pump_nb;
sleep 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment