Command executed via Proc::Async is not the correct “tapped”
I have one like this… Directly from the documentation
my $proc = Proc::Async.new: ‘raku’, ‘script.raku’;
$proc.stdout.tap(-> $v { print "Output: $v" }, quit => { say 'caught exception ' ~ .^name });
$proc.stderr.tap(-> $v { print "Error: $v" });
my $promise = $proc.start;
Thread.start: { await $promise; }
sleep 30;
The script generates data on stdout and stderr.
but
It prints only one line:
Output: Something
It stops printing information… The script produces more output…
What could be the problem?
Solution
You need to add an await $promise
to the end of the program, otherwise it may exit before the program you called finishes running.
Update (after the OP edits his post).
The OP also said to close stackoverflow:
The full output is printed when the program ends.. with a considerable delay.
If this is the case, the problem is most likely with the called program, which buffers its STDOUT (and possibly STDERR), so the watcher can’t even access its output ahead of time.
Calling flush may be helpful on the appropriate handle to the called program.