Why doesn't Perl 6 handle nonzero output in shell ()?

This try gets an exception:

try die X::AdHoc;
say "Got to the end";

The output shows that the program continues:

 Got to the end

If I try with the help of a shellcommand that does not exit with 0, the attempt will not catch it:

try shell('/usr/bin/false');
say "Got to the end";

The result does not look like an exception:

The spawned command '/usr/bin/false' exited unsuccessfully (exit code: 1)
  in block <unit> at ... line ...

What happens, does this make an attempt?

+6
source share
1 answer

The answer is indeed provided by Jonathan Worthington:

https://irclog.perlgeek.de/perl6-dev/2017-04-04#i_14372945

In short, shell () returns a Proc object. At the moment when this object is sunk, it will throw an exception, which it is internal if the program launch failed.

$ 6 'dd shell("/usr/bin/false")'
Proc.new(in => IO::Pipe, out => IO::Pipe, err => IO::Pipe, exitcode => 1, signal => 0, command => ["/usr/bin/false"])

, , Proc , :

$ 6 'my $result = shell("/usr/bin/false"); say "Got to the end"'
Got to the end

$result.exitcode, , .

+5

Source: https://habr.com/ru/post/1016285/


All Articles