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.
Add a comment
|
2 Answers
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.
3 Comments
Rahul
i used your method, but its giving 127. but i am using exit 0 in my shell script. so, i need a 0 instead of 127.
Zaid
@Rahul :
$? & 127 will give you what you want, as explained in the linked documentation.Rahul
ok i got. now how can i pop up a alert box in the perl script or using javascript inside perl.
In case of exit 0:- shell script returns 0 to perl script $? variable
but for exit 1 case:-it return 256 so needed to be shifted by 8 therefore try this:
#!/usr/bin/perl
print "pelr";
system("./shell.sh");
$p=$?>>8;
print $p;
NOTE- in shell script just put exit 0 and run and then exit 1. and see the o/p
Just a note, when using system in perl, it returns the exit code multiplied by 256. So, if a command returns 1, system("command") will return 256. So, to get the real return value, divide by 256.