2011-08-05 27 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

相關問題