How To Process System Exit Codes Using Perl Eval
erics, March 9th, 2021
The trick to using eval to catch shell execution is to return twice, once inside the eval and once outside:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
sub isMaintenance { my $return = eval { my $err=system("check_policy.sh | grep 'Policy is MAINTENANCE' >/dev/null 2>/dev/null"); &debug("perl error code: $err"); $err=$err / 256; &debug("system error code: $err"); if ($err != 0) { # Not Maintenance if ($verbose) { warn "policy is NOT MAINTENANCE\n"; } return 0; } else { return 1; } }; return $return; } |
Neat!