smgfc has asked for the wisdom of the Perl Monks concerning the following question:
Ok, I am playing around with forks and pipes and am trying to write from the parent process to a child process (created with Proc::Fork, which i adore), but the child will read from the pipe until it recieves and EOF. The only way I know to do this to send this is to close the pipe. In the rather terrible example below this lack of knowledge is fatal.
use Proc::Fork; use IO::Pipe; my ($pipe) = new IO::Pipe; child { $pipe->reader(); while (1) { while ($num = <$pipe>) { } print "Child: $num\n" if $old_num != $num; $old_num = $num; last if $num == 644; } exit; }; $pipe->writer(); while (1) { $in = <>; chomp $in; print $pipe $in; last if $in == 644; }
This outputs all the things I have sent over pipe together. It wont break them apart. When I enter 644 the parent dies (closing the pipe), and the child prints the string of numbers it recieved and then just goes on without a care in the world. I have tried putting lasts in the child while loop (ie.
While ($num = <$pipe>) {
last;
}
and that doesn't work. Any ideas are more then welcome. For the record i have super searched and perldoc'ed IO::Pipe. Cant find the answer anywhere. I know if you use IO::Handle you can do something like $pipe->eof;, but know how to integrate IO::Pipe and IO::Handle.
INPUT: 5 62 345 23 644 OUTPUT: Child: 56234523644 Desired OUTPUT: Child: 5 Child: 62 Child: 345 Child: 23 Child: 644
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending EOF to pipe
by Zaxo (Archbishop) on Jul 03, 2002 at 04:16 UTC | |
|
Re: Sending EOF to pipe
by rsteinke (Scribe) on Jul 03, 2002 at 03:25 UTC | |
|
•Re: Sending EOF to pipe
by merlyn (Sage) on Jul 03, 2002 at 15:55 UTC |