jjm*_*elo 8 asynchronous stdout pipe process perl6
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";
Run Code Online (Sandbox Code Playgroud)
(添加了一些修改,比如等待承诺).但是,我不知道如何打印输出$p
.添加tap
产生此错误:
Cannot both bind stdout to a handle and also get the stdout Supply
Run Code Online (Sandbox Code Playgroud)
在bind-stdout.p6第8行的块中
文档中有print
写入和写入方法,但read
除了阅读文件之外,我不知道如何使用它.任何的想法?
我不确定你能做到这一点(错误很明确).作为一种解决方法,您可以定期点击并打印到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";
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
146 次 |
最近记录: |