Skip to content

Commit 38ed8fb

Browse files
authored
Expand run section
- Show how nice «...» is with `run` - Include info that sunk procs explode and how to deal with it
1 parent e1a6ab5 commit 38ed8fb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

doc/Type/IO.pod6

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,24 @@ spurt 'file-that-already-exists', 'new text', :createonly;
335335
336336
sub run(*@args ($, *@) --> Proc)
337337
338-
Runs an external command without involving a shell and returns a Proc object.
338+
Runs an external command without involving a shell and returns a L<Proc> object.
339339
340340
run 'touch', '>foo.txt';
341341
342342
run Q:w{rm >foo.txt}; # Another way to use run, using word quoting for the
343343
# arguments
344344
345+
A sunk L<Proc> object for a process that L<exited|/routine/exitcode> unsuccessfully
346+
will throw. If you wish to ignore such failures, simply use L<run> in non-sink context:
347+
348+
run 'false'; # SUNK! Will throw
349+
run('false').so; # OK. Evaluates Proc in Bool context; no sinking
350+
345351
To capture output or error you can use the C<:out> or C<:err> arguments respectively:
346352
347-
my $proc = run 'echo', 'Perl 6 is Great!', :out, :err;
348-
with $proc.out { say .get; .close } # OUTPUT: «Perl 6 is Great!␤»
349-
with $proc.err { say .get; .close } # OUTPUT: «Nil␤»
353+
my $proc = run «echo 'Perl 6 is Great!'», :out, :err;
354+
$proc.out.slurp(:close).say; # OUTPUT: «Perl 6 is Great!␤»
355+
$proc.err.slurp(:close).say; # OUTPUT: «␤»
350356
351357
See L<Proc|/type/Proc> and L<Proc::Async|/type/Proc::Async> for more details.
352358

0 commit comments

Comments
 (0)