我试图在另一个 exe 成功执行时有条件地从批处理文件有条件地运行一个 exe。
我尝试了 IF 和 ERRORLEVEL 的几种不同组合,但似乎都不起作用
"..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008r2
IF %ERRORLEVEL% 1(
"..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008
)
Pause
给我错误
1(此时出乎意料。
我这里哪里出错了?
IF ERRORLEVEL ...
是自 DOS 时代以来就支持的特殊语法,%ERRORLEVEL%
WinNT 中添加了变量支持。
原来的语法是这样使用的:
call someapp.exe
if errorlevel 1 goto handleerror1orhigher
echo succuess...
要使用该变量,请使用正常的 IF 语法:if %errorlevel%==0 echo success...
注意%errorlevel%
如果有人这样做就停止工作set errorlevel=foo
并且它可能不会针对内部 cmd.exe 命令进行更新。
另一种解决方案是使用&&
:
call someapp.exe && (echo success) || (echo error!)
有(至少)两种已知的错误级别被破坏的情况,您必须使用||
反而:
- RD/RMDir https://stackoverflow.com/questions/11137702/batch-exit-code-for-rd-is-0-on-error-as-well
- >文件重定向 https://stackoverflow.com/questions/10354016/file-redirection-in-windows-and-errorlevel
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)