批处理文件测试误差水平 [英] batch file test error level

查看:108
本文介绍了批处理文件测试误差水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有条件在成功执行另一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆