icylisper has asked for the wisdom of the Perl Monks concerning the following question:
Above is the client code that writes/reads from a socket. Usage: ./client, and then input through STDIN to write to the socket. Is there a way I can pass $ARGV[0] in the child process like: print $socket $ARGV[0] ?use IO::Socket::INET; my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => '9000', Proto => 'tcp', Type => SOCK_STREAM ) or die "Error: cant create listening socket: $!\n"; $socket->autoflush(1); # so output gets there right away die "can't fork: $!" unless defined( $kidpid = fork() ); #parent process if ($kidpid) { while ( defined( my $line = <$socket> ) ) { print STDOUT $line; } kill( "TERM", $kidpid ); # send SIGTERM to child } #the child process else { my $line = <STDIN>; while ( defined($line) ) { print $socket $line; } } close($socket);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pass ARGV to STDIN
by alexm (Chaplain) on Mar 07, 2008 at 20:01 UTC | |
by icylisper (Initiate) on Mar 08, 2008 at 06:29 UTC | |
by almut (Canon) on Mar 08, 2008 at 08:36 UTC | |
by icylisper (Initiate) on Mar 08, 2008 at 14:27 UTC | |
by alexm (Chaplain) on Mar 08, 2008 at 09:00 UTC | |
|
Re: pass ARGV to STDIN
by Joost (Canon) on Mar 07, 2008 at 18:48 UTC | |
|
Re: pass ARGV to STDIN
by almut (Canon) on Mar 07, 2008 at 18:55 UTC |