7

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.

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@Rahul : $? & 127 will give you what you want, as explained in the linked documentation.
ok i got. now how can i pop up a alert box in the perl script or using javascript inside perl.
7

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.