Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to capture exit code of a perl script which is called from a shell script

I have this sample perl code, where $a $b $c values can be changed and has exit code $ex. I call this from another shell script, which is affected by abc.pl’s exit code. How do I capture just the exit code of this perl.

my $a=0; my $b=0; my $c=0;
my $sum = $a+$b+$c; $ex = 0;
if($sum == 0){
    print "success"; print " $ex \n";
}else{
    $ec=1 ; print "Not success"; print " $ex \n";
}
exit $ex;

Sample shell script.

echo start
set ecd = `abc.pl`
echo $ecd
echo stop

Here $ecd prints whatever is the output of abc.pl, but not just the exit code.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

$? contains the exit code of the last executed command.

set ecd = `abc.pl`
set status = $?
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading