批处理文件测试误差水平 [英] batch file test error level
问题描述
我想有条件在成功执行另一个EXE有条件运行批处理文件exe文件。
I'm trying to conditionally run an exe from a batch file conditionally upon another exe executing successfully.
我试过IF和ERRORLEVEL几个不同的组合,但似乎没有工作。
I've tried a few different combinations of IF and ERRORLEVEL but none seem to work
"..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008r2
IF %ERRORLEVEL% 1(
"..\..\..\TeamBuildTypes\Current Branch\DatabaseUpdate.exe" -s localhost\sql2008
)
Pause
给我的错误
1(在这个时候意外。
1( was unexpected at this time.
我在哪里去错在这里?
推荐答案
如果ERRORLEVEL是自DOS时代所支持的特殊语法,在WINNT中加入%ERRORLEVEL%变量的支持。
IF ERRORLEVEL is a special syntax supported since the DOS days, the %ERRORLEVEL% variable support was added in WinNT.
原来的语法使用这样的:
The original syntax is used like this:
call someapp.exe
if errorlevel 1 goto handleerror1orhigher
if errorlevel 0 echo succuess...
要使用变量,使用正常IF语法:如果%ERRORLEVEL%= = 0呼应的成功...
To use the variable, use the normal IF syntax: if %errorlevel%==0 echo success...
请注意,%ERRORLEVEL%停止工作,如果有人设置错误级别= foo的
键,它可能无法得到更新内部的cmd.exe命令。
Note that %errorlevel% stops working if someone does set errorlevel=foo
and it might not get updated for internal cmd.exe commands.
另一种解决方案是使用与放大器;&放大器;
An alternative solution is to use &&:
call someapp.exe && (echo success) || (echo error!)
这篇关于批处理文件测试误差水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!