# run: no shell (safe)
my $proc = run 'ls', '-l', :out, :err;
my $output = $proc.out.slurp(:close);
say "exit: {$proc.exitcode}";
say $output.lines.head(3);
# shell: uses the system shell (careful with user input)
my $sh = shell 'echo $HOME | tr a-z A-Z', :out;
say $sh.out.slurp(:close);
# Check success
my $r = run 'false';
say $r.so ?? 'ok' !! "failed with {$r.exitcode}";
# A failed Proc that's sunk throws X::Proc::Unsuccessful
# Feed input
my $sort = run 'sort', :in, :out;
$sort.in.say($_) for <banana apple cherry>;
$sort.in.close;
say $sort.out.slurp(:close);
# Proc::Async: asynchronous, streaming output
my $ping = Proc::Async.new('ping', '-c', '3', 'localhost');
react {
whenever $ping.stdout.lines { say "OUT: $_" }
whenever $ping.stderr { note "ERR: $_" }
whenever $ping.start { say "exited with {.exitcode}"; done }
whenever Promise.in(10) { $ping.kill; done }
}
# Environment and working directory
run 'pwd', :cwd('/tmp'), :env(%(|%*ENV, MY_VAR => 'x'));
say %*ENV<PATH>.split(':').head;