为什么当 .bat 文件在运行 .NET 应用程序后测试 %ERRORLEVEL% 时,它测试的是字符串返回类型,而不是 int?
我正在研究如何从命令行或在bat文件中运行.NET应用程序,并且给出了此代码用于测试应用程序的%ERRORLEVEL%(现有返回值):
@if "%ERRORLEVEL%" == "0" goto success
为什么它测试“0” “而不是0?据我了解,.NET 可执行文件在退出时返回一个 int,而不是一个字符串。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它只是将数值强制转换为字符串并进行比较。如果环境变量没有值,这会很有帮助,因此 %PARAM% == 1 将计算为 == 1,这会导致错误。
要检查程序的错误级别,最好按照 Raymond 进行评估陈的博客。
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.