我试图在另一个 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( was unexpected at this time.
我哪里出错了?
最佳答案
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
>
file redirection 关于error-handling - 批处理文件测试错误级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6812484/