#1 22 Sep 2016 13:03

dbenham
Member
From: U.S. east coast
Registered: 15 Apr 2012
Posts: 109

Faulty %=ExitCode% and %=ExitCodeASCII% documentation

Your documentation at http://ss64.com/nt/syntax-variables.html incorrectly states that %=ExitCode% and %=ExitCodeASCII% report on the value returned by EXIT /B.

These two dynamic variables ignore the ERRORLEVEL returned by EXIT /B, or any other internal command.

They only report on the most recent exit code returned by an external command, such as CMD /C EXIT n

Note also that these variables are true variables that are automatically set upon termination of an external command. So the values will be lost upon ENDLOCAL. See http://stackoverflow.com/a/20169219/1012053 for more information about the nature of various dynamic variables.

@echo off
setlocal

echo test EXIT /B 65
call :testExitB 65
echo %%ErrorLevel%%     = %errorlevel%
echo %%=ExitCode%%      = %=exitcode%
echo %%=ExitCodeASCII%% = %=exitcodeascii%
echo(

echo test CMD /C EXIT 65
cmd /c exit 65
echo %%ErrorLevel%%     = %errorlevel%
echo %%=ExitCode%%      = %=exitcode%
echo %%=ExitCodeASCII%% = %=exitcodeascii%
echo(

echo test EXIT /B 66
call :testExitB 66
echo %%ErrorLevel%%     = %errorlevel%
echo %%=ExitCode%%      = %=exitcode%
echo %%=ExitCodeASCII%% = %=exitcodeascii%
echo(

echo test CMD /C EXIT 66
cmd /c exit 66
echo %%ErrorLevel%%     = %errorlevel%
echo %%=ExitCode%%      = %=exitcode%
echo %%=ExitCodeASCII%% = %=exitcodeascii%
echo(

echo after ENDLOCAL
endlocal
echo %%ErrorLevel%%     = %errorlevel%
echo %%=ExitCode%%      = %=exitcode%
echo %%=ExitCodeASCII%% = %=exitcodeascii%
echo(
exit /b

:testExitB
exit /b %1

--OUTPUT--

test EXIT /B 65
%ErrorLevel%     = 65
%=ExitCode%      =
%=ExitCodeASCII% =

test CMD /C EXIT 65
%ErrorLevel%     = 65
%=ExitCode%      = 00000041
%=ExitCodeASCII% = A

test EXIT /B 66
%ErrorLevel%     = 66
%=ExitCode%      = 00000041
%=ExitCodeASCII% = A

test CMD /C EXIT 66
%ErrorLevel%     = 66
%=ExitCode%      = 00000042
%=ExitCodeASCII% = B

after ENDLOCAL
%ErrorLevel%     = 66
%=ExitCode%      =
%=ExitCodeASCII% =

Dave Benham

Offline

#2 22 Sep 2016 21:49

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 867
Website

Re: Faulty %=ExitCode% and %=ExitCodeASCII% documentation

Thanks Dave, I have updated the page now to rectify this.

Offline

Board footer

Powered by FluxBB