develooper Front page | perl.perl6.users | Postings from July 2017

Bi-directional communication with another process

Thread Next
From:
Norman Gaywood
Date:
July 27, 2017 23:50
Subject:
Bi-directional communication with another process
Message ID:
CAHJ-_U5wC+z4OjzJprWMZgrvrRizjyG39s1QA3=nTcg1qvGudw@mail.gmail.com
From inside a program I'd like to send some input to the stdin of external
program and read back the stdout.

The example in https://docs.perl6.org/language/ipc under proc comes close
to what I want:

my $echo = run 'echo', 'Hello, world', :out;
my $cat  = run 'cat', '-n', :in($echo.out), :out;
say $cat.out.get;
$cat.out.close();

That works, however what I want however is a single external process, sort
of like:

my $input = q:to/EOS/;
line of text
another line
EOS

my $cat  = run 'cat', '-n', :in($input.print), :out;
my $output = $cat.out.get;
$cat.in.close;
$cat.out.close;

say "done";
say $output;

But that is not correct. I seem to be missing something.

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