asynchronous - 使用 Proc::Async 从绑定(bind)管道中读取

标签 asynchronous process pipe stdout raku

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/

相关文章:

node.js - Nodejs异步更新数组时出现问题

javascript - 在未定义的循环中将数据保存到mongoDB

linux - 什么是CPU系数?

ruby-on-rails - 如何从 Rails 应用程序管理长时间运行的进程?

bash - 将与模式匹配的最后一个文件的名称保存到 bash 中的变量

c - 父进程无法读取 C 中 4 个不同管道的所有消息

javascript - 移动设备上的 AJAX 请求不起作用

c# - 为什么 TaskFactory.FromAsync() 重载需要提供状态对象?

Android:如何停止/清除我的 Android 小部件应用程序的缓存后台进程?

linux 管道参数列表太长