1

Possible Duplicate:
How do I get the application exit code from a Windows command line?

The Perl script that I'm calling inside batch returns a 1, 2, or 3. What's the syntax for calling this perl sript with an argument 829, and capturing the script's exit code?

 Perl.exe listMembership.pl 829 in cmd.exe

 @echo off
 set retVal=Perl.exe listMembership.pl 829
 echo %retVal%
1
  • @KeithThompson - it was 24% just less than hour ago... Commented Jul 3, 2012 at 22:31

1 Answer 1

2

Take a look at the output of if /? on the command line. Without cmd extensions, the lowest common denominator batch script would be something along the lines of:

@echo off
Perl.exe listMembership.pl 829
if errorlevel 4 goto error
if errorlevel 3 goto exit3
if errorlevel 2 goto exit2
if errorlevel 1 goto exit1
if errorlevel 0 goto exit0

:error
echo:Unexpected exit code %ERRORLEVEL%
goto end

:exit3
echo:Forbnicate
goto end

:exit2
echo:Colormaticate
goto end

:exit1
echo:Motorcade
goto end

:exit0
echo:Is this really success?
goto end

:end
echo:Done

Keep in mind, errorlevel checks have to be in descending order because:

ERRORLEVEL number Specifies a true condition if the last program run
                returned an exit code equal to or greater than the number
                specified.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.