Dan*_*ell 18 error-handling batch-file
我试图在另一个exe成功执行的条件下有条件地从批处理文件中运行exe.
我尝试了几种不同的IF和ERRORLEVEL组合,但似乎都没有效果
"..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008r2
IF %ERRORLEVEL% 1(
"..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008
)
Pause
Run Code Online (Sandbox Code Playgroud)
给我错误
1(此时出乎意料.
我在哪里错了?
And*_*ers 42
IF ERRORLEVEL ...是自DOS日以来支持的特殊语法,%ERRORLEVEL%在WinNT中添加了变量支持.
原始语法使用如下:
call someapp.exe
if errorlevel 1 goto handleerror1orhigher
echo succuess...
Run Code Online (Sandbox Code Playgroud)
要使用该变量,请使用常规IF语法: if %errorlevel%==0 echo success...
请注意,%errorlevel%如果有人停止工作,则set errorlevel=foo内部cmd.exe命令可能无法更新.
另一种解决方案是使用&&:
call someapp.exe && (echo success) || (echo error!)
Run Code Online (Sandbox Code Playgroud)
有(至少)两个已知的情况,其中errorlevel被破坏,你必须使用||:
| 归档时间: |
|
| 查看次数: |
84564 次 |
| 最近记录: |