Course of Raku / Objects, I/O, and exceptions / Input and output / Running external programs 🆕 / The Proc object

Quiz — The Proc object

What does the following program print?

my $proc = run 'sh', '-c', 'exit 2', :out;
$proc.out.slurp(:close);
say $proc.exitcode;
00
12
0True
0an error

.exitcode is the integer the program returned — here the shell was told to exit 2, so it is 2. The program does not throw: the failing Proc is stored in $proc and inspected with .exitcode, and looking at the result counts as handling it. (An exception would only arise if a failing Proc were discarded unchecked.)

Course navigation

The Proc object   |   The environment