2011-08-05 83 views

回答

5

如果execute.cmd返回一个整数比,你可以使用一个IF command检查它的返回值,如果它符合期望的人比你可以打电话launch.cmd

假设execute.cmd返回0,如果它是成功或整数> =否则为1。该批次是这样的:

rem call the execute command 
call execute.cmd 
rem check the return value (referred here as errorlevel) 
if %ERRORLEVEL% ==1 GOTO noexecute 
rem call the launch command 
call launch.cmd 

:noexecute 
rem since we got here, launch is no longer going to be executed 

注意,rem命令用来征求意见。

HTH,
JP

+0

exceute.cmd如果成功返回0,如果不成功则返回1,所以问题用你的逻辑解决了,非常感谢。正如你首先回答,我接受你的答案,尽管@jhclark的回答看起来是正确的。 – Anand

+0

@Anand K Gupta your wellcome :) –

+0

您也可以通过这种方式使用Windows Batch &&组合实现同样的功能:call execute.cmd && call launch.cmd – Aacini

3

我相信这是How do I make a batch file terminate upon encountering an error?重复。

你这里的解决办法是:

call execute.cmd 
if %errorlevel% neq 0 exit /b %errorlevel% 
call launch.cmd 
if %errorlevel% neq 0 exit /b %errorlevel% 

不幸的是,它看起来像Windows批处理文件没有等同的UNIX bash的set -eset -o pipefail。如果您愿意放弃非常有限的批处理文件语言,则可以尝试Windows PowerShell。

+0

谢谢,你也是.. – Anand

相关问题