I was looking at how to run a .NET app from the 开发者_开发问答command line, or in a bat file, and this code was given for testing the %ERRORLEVEL% (the exiting return value) of the application:
@if "%ERRORLEVEL%" == "0" goto success
Why is it testing for "0" and not 0? As I understand it, the .NET executable is returning an int when it exits, not a string.
It's just coercing the numeric value to a string and comparing. This can be helpful if an environment variable has no value so %PARAM% == 1 would evaluate to == 1 which would cause an error.
For checking a program's ERRORLEVEL, it's better to evaluate as per Raymond Chen's blog.
IF ERRORLEVEL 1 ECHO error level is 1 or more
精彩评论