You can't do this (well you can but it won't DWIM):
eval { system("perl 2.pl"); }; if($@) { print "the error that was thrown in 2.pl"; } ...
all it does is see if system("perl 2.pl") is valid perl regardless of 1) whether the system call succeeds or fails and 2) what happens when 2.pl actually runs. A system call may confuse you because if it *succeeds* it will return 0 (false) and if it fails it will return true! Thus you can't do:
system("blah") or die "Can't blah $!\n";
because this will die when it works! The reason is that in *nix programing if a program suceeds it exits with a value of 0. If it fails it exits with a numerical value that corresponds to the error code.
In the real world, in 1.pl you would have:
my $ret_val = system("perl 2.pl"); if ( $ret_val == 0 ) { print "Success"; } else { printf "Error. Err Number: %d", $ret_val<<8; }
And in 2.pl you would have:
exit 0 if $success; exit $err_num if $err_num; # numerical error value exit -1; # WTF???
Usually you would exit with the error number or exit 0 at the (sucessful) end of the script.
</code>open F, $file or do { warn "Can't open $file for read $!\n"; exit 1; # Error code for can't open file } do_stuff(*F); close F; exit 0;
In reply to Re: system command
by tachyon-II
in thread system command
by palette
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |