You have to close the writing end of the pipe in the parent. The fork duplicates the pipe's handles, and the readline (i.e. my @val = <READ>) doesn't stop reading until the pipe is fully closed (i.e. in both child and parent).
This should work:
... sub _Forked { my $ip = shift; pipe (READ,WRITE); die "Couldn't fork" unless defined (my $pid = fork()); if ($pid == 0) { # CHILD my @ping = `ping $ip -w 2 -q | sed -n '\$p'`; close (READ); select WRITE; print "@ping\n"; close (WRITE); # exit (0); } # close WRITE; # <--- return ($pid); } ...
Note that you have to move the creation of the pipe into the _Forked() routine (otherwise you'd have a dysfunctional pipe with a closed writing end upon subsequent calls of the routine...).
That said, I'm not sure why you're using an array here, as you seem to be outputting the last line of the ping only, anyway. But maybe this is just an oversimplified example.
In reply to Re: Reading from a pipe
by Eliya
in thread Reading from a pipe
by hello_world
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |