Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Non-blocking pipe write

by borisz (Canon)
on Nov 04, 2004 at 16:54 UTC ( #405218=note: print w/replies, xml ) Need Help??

in reply to Non-blocking pipe write

You mean like this?
use strict; use warnings; use IO::Socket; my $handle; my $pid; if (!defined($pid = open($handle, "|-"))) { die "Fork failed: ".$!; } elsif ($pid == 0) { # Child stdin->blocking(0); sleep(5); exit 0; } else { # Parent $handle->autoflush(1); $handle->blocking(0); my $i = 0; my $result; do { $result = print $handle "ABC\n"; print "PIPE write ".++$i."\n"; } while ($i < 10000); }

Replies are listed 'Best First'.
Re^2: Non-blocking pipe write
by Marcello (Hermit) on Nov 04, 2004 at 18:37 UTC
    I tried your code but now 1025 messages are written and then the parent blocks again... Any idea why?

      Hmm, no it should not block, the print should return and $result is undefined if the print fail. thats all.
        I'm trying to run it under win32 and it doesn't block, but it also doesn't appear to be forking. That is, the child process isn't running at all, yet the "die" doesn't happen, either. I'm also getting a "bad command or file name" message, which seems to be a result of the open($handle, "|-") call. Problem opening a pipe in a win32 machine?
        Hang on - it isn't running under FreeBSD for me, either:
        Can't use an undefined value as a symbol reference at line 8.
        and then it quits. Line 8 is:
        if (!defined($pid = open($handle, "|-"))) {
        I'm just playing with this trying to learn. Sounds like the open is failing. What am I missing? Update: Well, I understand that $handle is undefined at that point. What I am wondering is what it should be.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://405218]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2020-07-02 06:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found