in reply to Non-blocking pipe write

Look into the select RBITS, WBITS, EBITS in perlfunc, and/or IO::Select. caveat: select doesn't work on pipes in Windows.

Replies are listed 'Best First'.
Re^2: Non-blocking pipe write
by Marcello (Hermit) on Nov 04, 2004 at 18:58 UTC
    I tried:
    #!/usr/local/bin/perl use strict; use warnings; use IO::Handle; use IO::Select; my $handle; my $pid; if (!defined($pid = open($handle, "|-"))) { die "Fork failed: ".$!; } elsif ($pid == 0) { # Child sleep(5); exit 0; } else { # Parent $handle->autoflush(1); my $selector = IO::Select->new($handle); my $i = 0; do { if ($selector->can_write(0)) { print $handle "ABC\n"; print "PIPE write ".++$i."\n"; } else { print "PIPE cannot write\n"; } } while (1); }
    but only one pipe write is successful and then the can_write check fails every time. Can you be more specific please?

    FYI, I am on Linux

Re^2: Non-blocking pipe write
by BUU (Prior) on Nov 04, 2004 at 19:29 UTC
    Select mostly works on pipes in win32 (theres some strange behaviour but generally it works), select doesn't work on filehandles though.