Marcello has asked for the wisdom of the Perl Monks concerning the following question:
My questions:use strict; use warnings; use IO::Select; use IO::Socket; my $child = my $parent = my $pid = undef; # Create a socket pair for IPC (both ways) socketpair($child, $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC); $child->autoflush(1); $parent->autoflush(1); if (!defined($pid = fork())) { die $!; } elsif ($pid == 0) { close($child); print $parent "LINE1\nLINE2\n"; sleep(5); close($parent); exit 0; } else { close($parent); # Make sure the client has already started and sent the two lines sleep(2); my $ios = IO::Select->new($child); while (my @handles = $ios->can_read(0)) { foreach my $handle (@handles) { my $message = <$handle>; print "Read message: ".$message; } } close($child); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading from a pipe line by line
by ikegami (Patriarch) on Jan 17, 2006 at 20:30 UTC | |
by Marcello (Hermit) on Jan 17, 2006 at 20:57 UTC |