作者:罗丹灬_853 | 来源:互联网 | 2022-12-17 15:57
Proc::Async
是Perl 6用于与系统异步交互的类之一.文档指定了这种绑定到外部程序输出的方式:
my $p = Proc::Async.new("ls", :out);
my $h = "ls.out".IO.open(:w);
$p.bind-stdout($h);
await $p.start;
say "Done";
(添加了一些修改,比如等待承诺).但是,我不知道如何打印输出$p
.添加tap
产生此错误:
Cannot both bind stdout to a handle and also get the stdout Supply
在bind-stdout.p6第8行的块中
文档中有print
写入和写入方法,但read
除了阅读文件之外,我不知道如何使用它.任何的想法?
1> nxadm..:
我不确定你能做到这一点(错误很明确).作为一种解决方法,您可以定期点击并打印到stdout和同一块中的文件:
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";
是的,这是正确的.您可以通过获取"Supply"来绑定句柄或从中读取.我们只能将一个东西绑定到目标进程标准句柄,因此这里的例外只是反映了Perl 6无法真正做多少的低级别限制.