proc object proc

Documentation for proc object proc, assembled from the following types:

language documentation Inter-Process Communication

From Inter-Process Communication

(Inter-Process Communication) proc object proc

Both run and shell return a Proc object, which can be used to communicate with the process in more detail. Please note that unless you close all output pipes, the program will usually not terminate.

my $git = run 'git''log''--oneline':out;
for $git.out.lines -> $line {
    my ($sha$subject= $line.split: ' '2;
    say "$subject [$sha]";
}
$git.out.close();

If the program fails (exits with a non-zero exit code), it will throw an exception when the returned Proc object is sunk. You can save it into a variable, even anonymous one, to prevent the sinking:

$ = run '/bin/false'# does not sink the Proc and so does not throw 

You can tell the Proc object to capture output as a file handle by passing the :out and :err flags. You may also pass input via the :in flag.

my $echo = run 'echo''Hello, world':out;
my $cat  = run 'cat''-n':in($echo.out), :out;
say $cat.out.get;
$cat.out.close();

You may also use Proc to capture the PID, send signals to the application, and check the exitcode.

my $crontab = run 'crontab''-l';
if $crontab.exitcode == 0 {
    say 'crontab -l ran ok';
}
else {
    say 'something went wrong';
}