> Something like this?
> my $p = run 'cat', '-n', :in, :out;
> $p.in.say($_) for <i bet on you raku>;
> $p.in.close;
> say $p.out.slurp;
*that* simple!!! perfect ... thanks a lot!
this isn't obvious to guess that '-' means "you can connect the
subprocess directly to the perl interpreter". i really think this
example is worth to be added in the documentation.
also, i guess that the way the example is written will cause some
infinite iowait when we write a big enough amount of data to fill the
buffer (i don't know if it's correct).
so maybe this exemple should be added too?
my $p = run 'cat', '-n', :in, :out;
for <i bet on you raku> {
$p.in.say($_);
say $p.out.lines(1)[0];
}
$p.in.close;
how about the attached patch?
regards
marc
diff --git a/doc/Type/independent-routines.pod6 b/doc/Type/independent-routines.pod6
index 6142ebd3..f456b970 100644
--- a/doc/Type/independent-routines.pod6
+++ b/doc/Type/independent-routines.pod6
@@ -536,6 +536,30 @@ creating a kind of I<pipe>:
my $proc = run "ls", "-alt", :out($ls-alt-handle);
# (The file will contain the output of the ls -alt command)
+The standard input can be redirected as well so a bidirectional communication
+can be establish with the run process.
+
+ my $p = run 'cat', '-n', :in, :out;
+ for <i bet on you raku> { $p.in.say($_) }
+ $p.in.close;
+ say $p.out.slurp;
+ # 1 i
+ # 2 bet
+ # 3 on
+ # 4 you
+ # 5 raku
+
+the last example isn't a good idea if you deal with a great amount of data so
+you can also interact with the process line by line.
+
+ my $p = run 'cat', '-n', :in, :out;
+ for <i bet on you raku> {
+ $p.in.say($_);
+ say $p.out.lines(1)[0];
+ }
+ $p.in.close;
+
+
These argument are quite flexible and admit, for instance, handles to
redirect them. See L<Proc|/type/Proc> and
L<Proc::Async|/type/Proc::Async> for more details.