how can we capture the exit code correctly when we call a command via 'system'? from the testcase below i consistently capture "-1" which the expectation is "0" for code1 and "1" for code2.
test1.pl
use feature qw(say);
use strict;
my $code = system("./test2.pl 0");
say "code1 = $code";
system("./test2.pl 0");
say "code1' = $?";
$code = system("./test2.pl 1");
say "code2 = $code";
system("./test2.pl 1");
say "code2' = $?";
test2.pl
use feature qw(say);
use strict;
say "arg = @ARGV[0]";
my $exit_code = @ARGV[0];
say "this is a dummy script which exit with $exit_code";
exit $exit_code;
Output:
% ./project_r/test.pl
code1 = -1
code1' = -1
code2 = -1
code2' = -1
systemalways uses/bin/sh(except on Windows), or no shell at all when it can parse the command itself (like in your case).