You are not logged in.
Your documentation at https://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
Thanks Dave, I have updated the page now to rectify this.
Offline