fishfry said:
What I mean is, when I call fork(), what is the sequence of fd
manipulations to get the output of the child process redirected so that
the parent can read it?
Open a pipe with READHANDLE and WRITEHANDLE before you fork. Then
fork and -- very important -- close READHANDLE in the child and
WRITEHANDLE in the parent. Now the parent can read from READHANDLE
everything the child writes to WRITEHANDLE. If you want to capture
the child's STDOUT, open STDOUT as a duplicate to WRITEHANDLE.
pipe R, W;
defined( my $pid = fork) or die "fork: $!";
if ( $pid ) {
close W;
print while <R>;
} else {
close R;
open STDOUT, '>&', fileno W;
print "$_\n" for qw( gaga gigi gugu);
}
Anno