cwood has asked for the wisdom of the Perl Monks concerning the following question:

I am attempting to learn IPC::Run so that I may implement some privilege separation between daemons for generic operations and specific things that require root.

My child is not returning anything to the parent, apparently because it's not reading from the parent via "while (<STDIN>) {}". How would I get the child to read what the parent sends? My example is below.

The "cat1" is from perldoc IPC::Run, and runs as expected when using cat as the child (I get back on stdout what I used for input). When I use my "wr2" script as the child I get nothing on the parent's stdout. When I use "wr2" separately on the command line I get what I expect:

$ echo 123123 | wr2 123123

I've googled at great length, but all the examples are about being the parent, not being the child.

This is cat1:

#!/usr/bin/perl use warnings; use strict; use IPC::Run qw(start pump finish timeout); #my @cat = qw(/bin/cat); my @cat = qw(/home/cwood/bin/wr2); my ($in, $out, $err); my $h = start \@cat, \$in, \$out, \$err, timeout(10); $in .= "some input\n"; pump $h until $out =~ /input\n/g; $in .= "some more input\n"; pump $h until $out =~ /\G.*more input\n/; $in .= "some final input\n"; finish $h or die "cat returned $?"; warn $err if $err; print $out; ## All of cat's output

This is wr2:

#!/usr/bin/perl use warnings; use strict; while (<STDIN>) { print; }

Replies are listed 'Best First'.
Re: How to be a child of IPC::Run?
by zentara (Cardinal) on Apr 30, 2012 at 10:33 UTC
      It's not my code, it's from the IPC::Run example. Thank you for the pointer, though. I will look into that.
        Responding to my own post is so awfully tacky, but if I add this before my for loop in wr2, my example works:
        $| = 1;
        Now I'll see if I can figure out the rest.