i want to pop up an alert box using perl script. I am using exit 0
to terminate the shell script successfully and exit 1
to terminate the shell script when an error occurs. I want to capture this exit code in the perl script. And depending on the value 0 or 1, I want to pop up an alert box with success or failure message respectively.
exit() function evaluates the expression passed to it and exits from the Perl interpreter while returning the value as the exit value. The exit() function does not always exit immediately but calls the end routines before it terminates the program.
To check the exit code we can simply print the $? special variable in bash. This variable will print the exit code of the last run command. $ echo $?
Examining exit code in Perl If you happen to execute one perl script from another, for example using the system function, Perl has the same variable $? containing the exit code of the "other program". The call to system will return the exit code and it will be also saved in the $? variable of Perl.
Extracting the elusive exit code To display the exit code for the last command you ran on the command line, use the following command: $ echo $?
You can check the exit code of another process with the child error variable $?
. For example:
system("perl foo.pl");
my $exit_val = $? >> 8; # now contains the exit value of the perl script
Read the documentation for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With