IPC-Run icon indicating copy to clipboard operation
IPC-Run copied to clipboard

suggest option for blocking output pipe [rt.cpan.org #101997]

Open toddr opened this issue 8 years ago • 1 comments
trafficstars

Migrated from rt.cpan.org#101997 (status was 'new')

Requestors:

Attachments:

From [email protected] on 2015-02-08 04:21:55:

I wanted to start a subprocess and send it data through a pipe like the
program below, but found run() "<pipe" handle is non-blocking, when
printing a big block or faster than the child reads (EWOULDBLOCK or
EAGAIN).

    Error from print to pipe: Resource temporarily unavailable at foo.pl line 5.

It could be good if the docs of "<pipe" described the non-blocking,
under the bit "The <pipe operator opens the write half of a pipe ...".
I presume the motivation is to allow simultaneous read and write or for
a master process to do other things when some child is not ready.

It could also be good to have an option for a blocking output pipe.
I see there's some deliberate fcntl() to turn off blocking, so the
option would not do that.

I think this would be useful in various cases where the perl program is
setting itself up as the start of a pipeline and so should write at the
pace of the child.

toddr avatar May 12 '17 12:05 toddr

foo.pl:

use strict;
use IPC::Run;
my $harness = IPC::Run::start(['wc'], '<pipe', \*WC)
  or die "Cannot run cat";
print WC "blah blah\n" x 32768
  or die "Error from print to pipe: $!";
close WC
  or die "Error closing pipe";
$harness->finish;

Output:

$>perl foo.pl 
Error from print to pipe: Resource temporarily unavailable at foo.pl line 5.
    6553   13108   65536

toddr avatar Mar 27 '18 00:03 toddr