routine run

Documentation for routine run assembled from the following types:

role IO

From IO

(IO) sub run

sub run(*@args ($*@) --> Proc)

Runs an external command without involving a shell and returns a Proc object.

run 'touch''>foo.txt'# Create a file named >foo.txt 
run <<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 $file = --my arbitrary filename;
run touch--$file;  # RIGHT 
run <touch -->$file;     # RIGHT 
run «touch -- "$file"»;    # RIGHT but WRONG if you forget quotes 
run «touch -- $file»;      # WRONG; touches ‘--my’, ‘arbitrary’ and ‘filename’ 
run touch$file;        # WRONG; error from `touch` 
run «touch "$file"»;       # WRONG; error from `touch` 

Note that -- is required for many programs to disambiguate between command-line arguments and filenames that begin with hyphens.

A sunk Proc object for a process that exited unsuccessfully will throw. If you wish to ignore such failures, simply use run in non-sink context:

run 'false';     # SUNK! Will throw 
run('false').so# OK. Evaluates Proc in Bool context; no sinking 

To capture output or error you can use the :out or :err arguments respectively:

my $proc = run 'echo''Perl 6 is Great!':out:err;
$proc.out.slurp(:close).say# OUTPUT: «Perl 6 is Great!␤» 
$proc.err.slurp(:close).say# OUTPUT: «␤» 

See Proc and Proc::Async for more details.

class Thread

From Thread

(Thread) method run

method run(Thread:D:)

Runs the thread, and returns the invocant. It is an error to run a thread that has already been started.