First of all, try to give us something that should work cut-and-paste if there was no error. This helps us concentrate on the problem you have instead of working out a new example from the scratch, and helps you have more answers.
Then, IO::Select says:
So it doesn't return the lines which wait to be read, but the handles that have data and that you can read from.can_read ( [ TIMEOUT ] ) Return an array of handles that are ready for reading. "TIMEOUT" is the maximum amount of time to wait before returning an empty list, in seconds, possibly frac- tional. If "TIMEOUT" is not given and any handles are registered then the call will block.
Last, but not least, you're maybe suffering from buffering. You don't provide much information about SOCKET/SOC, but note that if it buffers you could wait a long time before something is output. Unless it's really some socket, in which case you'd not.
Here's a working example, you'll be able to adapt it to your case easily. Note that the child sleeps 5 seconds, then checks for data in handles and reads from them.
As a final note, always check the return status of open, it can fail!#!/usr/bin/perl use warnings; use strict; use IO::Select; my $pid = open(PIP, "|-"); if ($pid < 0) { die "open(): $!"; } elsif ($pid > 0) { print scalar localtime time, " - Parent: sending something to chil +d\n"; print PIP "Hi, son!\n"; print scalar localtime time, " - Parent: waiting for child to fini +sh\n"; close PIP; print scalar localtime time, " - Parent: exiting\n"; } else { my $selector = IO::Select->new(\*STDIN); print scalar localtime time, " - Child: just born!\n"; sleep(60); my @handles = $selector->can_read(0); if (@handles) { print scalar localtime time, " - Child: there are " . scalar(@ +handles) . " handles ready for reading\n"; # It can only be STDIN... my $line = <STDIN>; chomp($line); print scalar localtime time, " - Child: parent says: [$line]\n +"; } print scalar localtime time, " - Child: exiting\n"; exit(0); } __END__ Sun May 22 15:43:48 2005 - Parent: sending something to child Sun May 22 15:43:48 2005 - Child: just born! Sun May 22 15:43:48 2005 - Parent: waiting for child to finish Sun May 22 15:44:48 2005 - Child: there are 1 handles ready for readin +g Sun May 22 15:44:48 2005 - Child: exiting Sun May 22 15:44:48 2005 - Parent: exiting
Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')
Don't fool yourself.In reply to Re: forked kid can't read from IO::Select->can_read
by polettix
in thread forked kid can't read from IO::Select->can_read
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |