Why does cmd.exe have different error level behavior on a 64-bit machine?

If I make a script package called temp.bat (for example) containing:

exit /b 1

When I launch it in various ways, I get a different behavior on my 32-bit XP system and 64-bit XP system.

In 32-bit mode:

> temp.bat
> echo %ERRORLEVEL%
1
> cmd /c temp.bat
> echo %ERRORLEVEL%
0

In 64-bit mode:

> temp.bat
> echo %ERRORLEVEL%
1
> cmd /c temp.bat
> echo %ERRORLEVEL%
1

I looked at the cmd.exe parameters, and I could not find any parameters that control how it distributes error level information from batch scripts. At the moment, I can not find a rational explanation for this difference.

+5
source share
2 answers

You must be careful with exit / b, as in all cases it does not work correctly. For example:

temp.bat&&echo 0||echo 1

temp.bat exit/b 1, , 1 , . , - @%COMSPEC% /C exit 1 last

+7

, .bat . .cmd, .

, .bat .cmd : .bat, cmd pre-NT CLI, command.com, .

, . , .bat/.cmd, .

+3

All Articles