Checking return/exit codes ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asearle
    New Member
    • Sep 2006
    • 39

    Checking return/exit codes ...

    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.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    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.

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      see die() instead of exit();

      Comment

      • shantu
        New Member
        • May 2007
        • 1

        #4
        Originally posted by KevinADC
        see die() instead of exit();
        As miller specified your answer is in the following link,

        http://perldoc.perl.or g/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 "$checkexit code >> 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

        Comment

        Working...