Documentation for routine
run assembled from the following types:
sub run(* ($, *@) --> Proc)
Runs an external command without involving a shell and returns a Proc object.
run 'touch', '>foo.txt'; # Create a file named >foo.txtrun <<rm >foo.txt>>; # Another way to use run, using word quoting for the# arguments
If you want to pass some variables you can still use
< >, but try to avoid using
« » as it will do word splitting if you forget to quote variables:
my = ‘--my arbitrary filename’;run ‘touch’, ‘--’, ; # RIGHTrun <touch -->, ; # RIGHTrun «touch -- "$file"»; # RIGHT but WRONG if you forget quotesrun «touch -- »; # WRONG; touches ‘--my’, ‘arbitrary’ and ‘filename’run ‘touch’, ; # WRONG; error from `touch`run «touch "$file"»; # WRONG; error from `touch`
-- is required for many programs to disambiguate between command-line arguments and filenames that begin with hyphens.
run 'false'; # SUNK! Will throwrun('false').so; # OK. Evaluates Proc in Bool context; no sinking
To capture output or error you can use the
:err arguments respectively:
my = run 'echo', 'Perl 6 is Great!', :out, :err;.out.slurp(:close).say; # OUTPUT: «Perl 6 is Great!␤».err.slurp(:close).say; # OUTPUT: «␤»
Runs the thread, and returns the invocant. It is an error to run a thread that has already been started.