in reply to Re: Trouble using exit codes
in thread Trouble using exit codes

Hi Eliya, Thanks a lot for the quick response !! It does work/display as I expected. It displays the error code that I am returning and the message. HOWEVER if I try this C:\perl>echo %ERRORLEVEL% command after execution of my script, I still get the value 0 for all the cases. Now am wondering if the above command is right or not for determinig the error code/exit code value.(I read somewehere that above command is equivalent of echo $? in linux).

Replies are listed 'Best First'.
Re^3: Trouble using exit codes
by Eliya (Vicar) on Apr 06, 2011 at 20:19 UTC

    If you actually do want to exit the program, and pass some exit code to the calling process, there's nothing wrong with using exit.  In the above snippet, you could place the exit after the print, for example.

    ... print "exit code: $exitcode, message: '$msg'\n"; exit $exitcode;

    But note that negative exit codes are typically interpreted unsigned, e.g. in a Unix shell, -1 would turn into 255  (-2 into 254, etc.):

    $ perl -e "exit -1" $ echo $? 255
      You are Awesome !! Thank you Thank you.:) I hope I can program like you one day. "Bows" - Ram