Proc::Async
is one of the classes that Perl 6 uses for interacting asynchronously with the system. The documentation specifies this way to bind to the output of an external program:
my $p = Proc::Async.new("ls", :out);
my $h = "ls.out".IO.open(:w);
$p.bind-stdout($h);
await $p.start;
say "Done";
(Some modifications added, like awaiting for the promise). However, I don't know how to print the output of this $p
. Adding a tap
yields this error:
Cannot both bind stdout to a handle and also get the stdout Supply
in block at bind-stdout.p6 line 8
There are print
and write methods in the documentation, but I don't know how to read
from it other than reading the file. Any idea?
I am not sure you can do that (the error is very explicit). As a workaround you could get a regular tap and print to stdout and a file in the same block:
my $p = Proc::Async.new("ls", :out);
my $h = "ls.out".IO.open(:w);
$p.stdout.tap(-> $str { print $str; $h.print($str) });
await $p.start;
say "Done";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With