Proc::Async
是 Perl 6 用于与系统进行异步交互的类之一。文档指定了这种方式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";
(添加了一些修改,例如等待 promise )。但是,我不知道如何打印此
$p
的输出.添加 tap
产生此错误:Cannot both bind stdout to a handle and also get the stdout Supply
在 bind-stdout.p6 第 8 行的 block 中
有
print
and write methods在文档中,但我不知道如何 read
除了读取文件之外。任何的想法?
最佳答案
我不确定你能做到这一点(错误非常明确)。作为一种解决方法,您可以定期点击并打印到标准输出和同一 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";
关于asynchronous - 使用 Proc::Async 从绑定(bind)管道中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50313779/