got_it> line1
got_it> line2
got_it> line3
123
456
####
got_it> 123
got_it> 456
##
##
999
got_it> 777
got_it> 888
123
456
##
##
999
got_it> 777
got_it> 888
123
456
##
##
use strict;
use warnings;
use Socket;
# UPDATE #2: added 2 lines below
use Win32::Process;
use Win32;
my $bug_on = 1;
sub _pipe_from_fork ($) {
my $pid;
# emulate pipe()
my $WRITE;
socketpair($_[0], $WRITE, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
and shutdown($_[0], 1)
and shutdown($WRITE, 0)
or return undef;
if (defined($pid = fork()))
{
unless ($pid)
{
if ($bug_on)
{
# UPDATE #1: added 1 line below
close(STDOUT);
# XXX: BUG
open(STDOUT, ">&", $WRITE) or die;
}
else
{
print $WRITE "$_\n" for qw(line1 line2 line3);
}
}
}
return $pid;
}
my $pid = _pipe_from_fork(my $READ);
die unless defined($pid);
if ($pid)
{
print "got_it> $_" while <$READ>;
}
else
{
# UPDATE #1: added 1 line below
print `perl -le "print 777; print 888; print STDERR 999"`;
# UPDATE #2: commented exec line and added Win32::Process::Create()
#exec qw(perl -le), 'print 123; print 456' or die;
Win32::Process::Create(
my $obj,
'C:\\Perl\\bin\\perl.exe',
'C:\\Perl\\bin\\perl.exe -le "print 123; print 456"',
# does not inherit filehandles?
1,
NORMAL_PRIORITY_CLASS,
"."
);
}