469,326 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

Checking return/exit codes ...

39
Hallo everyone,

I have a perl script which can return error codes. I have done this with, for example, 'exit 11;', which would (I imagine) send the exit code 11 (instead of 0) back to the calling program.

I would now like to check that my error codes are being returned correctly and so wanted to write a short script to test this. Here I considered using the following ...

$checkexitcode = system ("perl myscript.pl");

but believe that this will simply catch the return/exit code from 'system' or from 'perl' and not the return code from 'myscript.pl'.

Can anyone help me with this? Maybe you already have a simple script to test for return codes?

Many thanks,
Alan Searle.
Jan 31 '07 #1
3 54918
miller
1,089 Expert 1GB
According to the documentation for both of those functions that should work:

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

I've never had any personal experience with that particular need, so you'll have to test to make sure (which is the whole point I know). But system is the correct command to use as far as I know, as exec does not return a value.
Jan 31 '07 #2
KevinADC
4,059 Expert 2GB
see die() instead of exit();
Jan 31 '07 #3
shantu
1
see die() instead of exit();
As miller specified your answer is in the following link,

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

$checkexitcode = system ("perl myscript.pl");

You were right. In the above command $checkexitcode is the return code from the system and not the exit code of myscript.pl

To get the return code of myscript.pl you should shift system exit code to right by 8. I mean "$checkexitcode >> 8" will give you the exit code from the myscript.pl.

Also "$?" is same as $checkexitcode. So you can also use "$?>>8" to get the exit code of script that you are executing
May 22 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by - ions | last post: by
2 posts views Thread by George Sakkis | last post: by
6 posts views Thread by RoSsIaCrIiLoIA | last post: by
16 posts views Thread by Fao, Sean | last post: by
5 posts views Thread by # include | last post: by
11 posts views Thread by =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= | last post: by
10 posts views Thread by =?iso-8859-1?q?Tom=E1s_=D3_h=C9ilidhe?= | last post: by
46 posts views Thread by Bill Cunningham | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.