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

Sending a string to a subprocess

Thread Next
From:
Sean McAfee
Date:
November 12, 2020 00:12
Subject:
Sending a string to a subprocess
Message ID:
CANan03aqY7+j7VNcSW2O8xZwzVF6UCX2BZUYmT+zgf+zy7vk5w@mail.gmail.com
I posted this question on Stack Overflow a few days ago:
https://stackoverflow.com/questions/64757138/raku-sending-a-string-to-a-subprocesss-standard-input

...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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About