By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Checking return/exit codes ...

P: 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");

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

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
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,089
According to the documentation for both of those functions that should work:

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

Expert 2.5K+
P: 4,059
see die() instead of exit();
Jan 31 '07 #3

P: 1
see die() instead of exit();
As miller specified your answer is in the following link,

$checkexitcode = system ("perl");

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

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

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.