develooper Front page | perl.perl6.users | Postings from November 2020

Sending a string to a subprocess

Thread Next
Sean McAfee
November 12, 2020 00:12
Sending a string to a subprocess
Message ID:
I posted this question on Stack Overflow a few days ago:

...but there haven't been any answers, so I'm asking here.

The tl;dr is that I don't see an obvious way to send data to a subprocess's
standard input stream, other than by creating a second subprocess.

For a simple example, suppose I wanted to store a file on a remote host
with ssh:

    my $content = 'file contents';
    run 'ssh', 'myhost', 'cat > outfile', :in($what-goes-here);

The only solution I've found after a lot of searching is not very appealing.

    my $echo = run 'echo', $content, :out;
    run 'ssh', 'myhost', 'cat > outfile', :in($echo.out);

Is there any better way?

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About