Operating System - HP-UX
1753797 Members
7036 Online
108805 Solutions
New Discussion юеВ

could not able to get right exit value from perl script

 
Goutam Maity
Occasional Contributor

could not able to get right exit value from perl script

Hi,

Please check below perl & shell script.

root@ > more test.pl
#!/usr/bin/perl


print " begining of programme \n";

$val=1;
$val=system("sh check.sh");


print "Exit Value : ",$?,"\n";
print "Value of veriable val : ",$val,"\n";





root@ > more check.sh

echo "Inside Shell Script..... check.sh......";
exit 123;


unixh147-root@ /home/gm433 > perl test.pl

begining of programme

Exit Value: 31488

Value of veriable val : 31488


Why I am not able to get correct value i.e. 123 ?

How can I get value 123?

Please help me.

Thanks,
Goutam




2 REPLIES 2
Steven Schweda
Honored Contributor

Re: could not able to get right exit value from perl script

You might get better answers sooner in a
forum related to your actual OS, which does
not appear to be VMS.
Craig A Berry
Honored Contributor

Re: could not able to get right exit value from perl script

You might read the docs:

$ perldoc -f system

or

http://perldoc.perl.org/functions/system.html

where it says,

"The return value is the exit status of the program as returned by the wait call. To get the actual exit value, shift right by eight."

So, if you shift the result right by 8, you get what you are looking for:

$ perl -e "$x=system('perl -e exit(123)'); print $x"
31488
$ perl -e "$x=system('perl -e exit(123)'); print $x >> 8;"
123

If you were using Perl on VMS (which you appear not to be) you could use the vmsish 'exit' pragma to control whether you get native exit codes or POSIX emulation.