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

start \@cat, '<pipe', \*IN; doesn't work as advertised (doesn't work at all?) [rt.cpan.org #121383]

Open toddr opened this issue 7 years ago • 2 comments

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

Requestors:

From [email protected] on 2017-04-26 05:11:35:

The perldoc has this example :

    @cat = ( 'cat' );
    ....
    $h = start \@cat, '<pipe', \*IN;
    print IN "hello world\n";
    pump $h;
    close IN;
    finish $h;

But it doesn't work... It hangs and never finishes. Swapping the pump and close lines, works, though. Like this:

    $h = start \@cat, '<pipe', \*IN;
    print IN "hello world\n";
    close IN;
    pump $h;
    finish $h;

I think I understand that - cat doesn't print until STDIN has been closed (although that doesn't jive with experiments in a normal terminal)

So then I tried this: Here I just need a single line of input. It also doesn't work:

    my $bashScript = <<'END';
    echo starting - Enter a line and press enter:
    read LINE
    echo Got line: $LINE
    echo ending
    END

    my $h = start ['bash', '-c', $bashScript], '<pipe', \*IN;
    print IN "hello world\n";
    pump $h;
    close IN;
    finish $h;

I don't actually understand why that doesn't work, when this does (using a scalar and '<' instead of a glob and '<pipe'):

    my $bashScript = <<'END';
    echo starting - Enter a line and press enter:
    read LINE
    echo Got line: $LINE
    echo ending
    END

    my $in = '';
    my $h = start ['bash', '-c', $bashScript], '<', \$in;
    $in .= "hello world\n";
    pump $h;
    finish $h;

However this does work. I can't explain that from reading the perldoc...

    my $bashScript = <<'END';
    echo starting - Enter a line and press enter:
    read LINE
    echo Got line: $LINE
    echo ending
    END

    my $h = start ['bash', '-c', $bashScript], '<pipe', \*IN, '>', sub {
print @_ };
    print IN "hello world\n";
    pump $h;
    close IN;
    finish $h;

Using IPC::Run version: 0.95, perl v5.20.2, debian jessie (stable).

-- Peter Valdemar Mørch http://www.morch.com

toddr avatar May 12 '17 12:05 toddr

@pmorch Are you wanting a docs patch here?

toddr avatar Mar 27 '18 00:03 toddr

Yes. Most likely.

At least the documented examples should work. So I'm asking for at least a documentation patch to fix that.

As I write, I don't understand the differences between the various scenarios above. Educating me on the details of terminal caching (e.g. why the order of pump and close matters) is perhaps not the purpose of the IPC::Run perldoc or the bug tracker, but if there is a simple explanation or, perhaps less likely, a bug somewhere I (and future perldoc readers?) wouldn't mind to understand where I went wrong.

pmorch avatar Mar 27 '18 02:03 pmorch