$ perl -w deleteme.pl Child live Parent live Handles: 1, 1 ready. [r][d:HELLO! :d] [W][W][r][d:HELLO! :d] [W][r][d:HELLO! :d] [W][r][d:HELLO! :d] [W][r][d:HELLO! :d]
Update: a couple of questions I would have are: why are you using while (<$pipe>) instead of sysread? Essentially the read code is entering an infinite loop as it reads, blocking line by line, the output from the child. Which I'm sure is not what you intended..
Update 2: maybe try the following:
use strict; use warnings; use IO::Pipe; use IO::Select; select( ( select( STDERR ), $| = 1 )[0] ); select( ( select( STDOUT ), $| = 1 )[0] ); my $pipe = new IO::Pipe; if ( fork() ) { print "Parent live\n"; $pipe->reader(); my $ios = IO::Select->new(); $ios->add($pipe); while (1) { my $handles = scalar( $ios->handles ); my @fh = $ios->can_read(1); print( STDERR "Handles: $handles, " . scalar(@fh) . " ready\n" ); foreach ( @fh ) { print( STDERR "[r]\n" ); my $buf = ""; sysread( $_, $buf, 1024 ); print( STDERR "[d:$buf:d]\n" ); } if ( ! @fh ) { print( STDERR "[b]\n" ); } } } else { print "Child live\n"; $pipe->writer(); $pipe->autoflush(1); while (1) { $pipe->print("HELLO!"); print( STDERR "[W]\n" ); sleep 3; } }
I suspect that if you're going to use IO::Select then the handles returned to you should be processed by sysread (and syswrite if you're checking for handles that can be written to) as these clear the select flags and process only that bit of data which is available right now. The <> syntax, on the other hand, blocks as far as I know.
Update 3: I can't get it to go with XP either.. using Perl v5.8.7 on MSWin32-x86-multi-thread and WinXP the IO::Select::select(undef, undef, undef, 1) call doesn't wait and it doesn't detect things being written to my pipe..
Update 4: See below for an INET socket approach..
In reply to Re: IO::Select on an IO::Pipe not doing anything
by monarch
in thread IO::Select on an IO::Pipe not doing anything
by FLEB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |