Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
toddr opened this issue May 12, 2017 · 2 comments
Labels
Docs A Documentation fix

Comments

@toddr
Copy link
Member

toddr commented May 12, 2017

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

Requestors:

From peter@morch.com 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
Copy link
Member Author

toddr commented Mar 27, 2018

@pmorch Are you wanting a docs patch here?

@toddr toddr added the Docs A Documentation fix label Mar 27, 2018
@pmorch
Copy link

pmorch commented Mar 27, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs A Documentation fix
Projects
None yet
Development

No branches or pull requests

2 participants