G
ghquick
I do not understand why the following command file gives different
errorlevels depending on the /B switch of the exit command (it works if
not in a for loop)
Commandfiles
echo test1,test2 >token.txt
ECHO EXIT 99 >EXIT99.CMD
ECHO EXIT /B 99 >EXIT99B.CMD
echo on
setlocal ENABLEDELAYEDEXPANSION enableextensions
for /F "eol=; tokens=1,2 delims=," %%I in (token.txt) do (
CMD /V:ON /CE:EXIT99B.CMD <\nul
echo !ERRORLEVEL!
)
echo !ERRORLEVEL!
for /F "eol=; tokens=1,2 delims=," %%I in (%token.txt) do (
CMD /V:ON /CE:EXIT99.CMD <\nul
echo !ERRORLEVEL!
)
echo !ERRORLEVEL!
Gives the following output:
echo !ERRORLEVEL!
)
echo !ERRORLEVEL!
)
c:agpw>EXIT /B 99
0
c:agpw>echo !ERRORLEVEL!
0
c:agpw>for /F "eol=; tokens=1,2 delims=," %I in (token.txt) do (
CMD /V:ON /CE:EXIT99.CMD 0<\nul
echo !ERRORLEVEL!
)
echo !ERRORLEVEL!
)
c:agpw>echo !ERRORLEVEL!
99
I thought both forms of the EXIT command EXITt /b 99 or EXITt 99
should return an error level of 99.
errorlevels depending on the /B switch of the exit command (it works if
not in a for loop)
Commandfiles
echo test1,test2 >token.txt
ECHO EXIT 99 >EXIT99.CMD
ECHO EXIT /B 99 >EXIT99B.CMD
echo on
setlocal ENABLEDELAYEDEXPANSION enableextensions
for /F "eol=; tokens=1,2 delims=," %%I in (token.txt) do (
CMD /V:ON /CE:EXIT99B.CMD <\nul
echo !ERRORLEVEL!
)
echo !ERRORLEVEL!
for /F "eol=; tokens=1,2 delims=," %%I in (%token.txt) do (
CMD /V:ON /CE:EXIT99.CMD <\nul
echo !ERRORLEVEL!
)
echo !ERRORLEVEL!
Gives the following output:
CMD /V:ON /CE:EXIT99B.CMD 0<\nulecho test1,test2 1>token.txt
ECHO EXIT 99 1>EXIT99.CMD
ECHO EXIT /B 99 1>EXIT99B.CMD
echo on
setlocal ENABLEDELAYEDEXPANSION enableextensions
for /F "eol=; tokens=1,2 delims=," %I in (token.txt) do (
echo !ERRORLEVEL!
)
CMD /V:ON /CE:EXIT99B.CMD 0<\nul
echo !ERRORLEVEL!
)
c:agpw>EXIT /B 99
0
c:agpw>echo !ERRORLEVEL!
0
c:agpw>for /F "eol=; tokens=1,2 delims=," %I in (token.txt) do (
CMD /V:ON /CE:EXIT99.CMD 0<\nul
echo !ERRORLEVEL!
)
CMD /V:ON /CE:EXIT99.CMD 0<\nul
echo !ERRORLEVEL!
)
99EXIT 99
c:agpw>echo !ERRORLEVEL!
99
I thought both forms of the EXIT command EXITt /b 99 or EXITt 99
should return an error level of 99.