open $fh, "-|";
does an implicit fork, and the STDOUT of the forked process (a copy of the actual process)
is connected to the lexical filehandle $fh.
The forked copy executes the rest of the script right after the fork, which is in the call to open().
fork() returns the process ID of the forked process in the parent, and zero in the child, that's
how open returns the child PID if opening a pipe.
So in your code the parent enters the if () { } block whith the open() conditional, the child doesn't:
it just does an exit(), which is not what you want.
Give your forked child some code to do:
my $pid = open $fh, "-|";
if ($pid) { # parent here. Read from child.
print "read from child: $_" while (<$fh>);
wait; # ...for the child to finish.
}
else { # child here. STDOUT connected to parent $fh
print while <STDIN>;
exit; # important, you don't want the child to execute
# the statements after this block!
}
# parent continues ...
That said, what the heck are you trying to do? Read data from apache? Just read STDIN.
Seems like you have an XY Problem.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|