On linux I get:
$ 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.