批处理文件,如果第一个命令退出则执行第二个命

时间:2010-06-02 11:30:43

标签: batch-file

我有一个批处理文件,updatesipversion.bat正在调用另一个批处理文件template.bat

updatesipversion.bat代码:

set init=empty
set main=svn propget svn:externals ./3c > install\msbuild\SipBranchDefaultDetailsTemplate.txt 
set error=update
set action=empty

call template.bat "%init%" "%main%" "%error%" "%action%"

set init=empty
set main=install\msbuild\SipBranchDetails.exe
set error=update
set action=empty

call template.bat "%init%" "%main%" "%error%" "%action%"

template.bat代码

set /a WAcounter=0
for %%a in (%*) do set /a WAcounter+=1
if not %WAcounter%==4 goto :Error
set WAinit=%1
set WAmain=%2
set WAerror=%3
set WAaction=%4
set /a WAcounter=0

:WAinitCommand
IF NOT %1=="empty" %WAinit:~1,-1%

:WAmainCommand
set /a WAcounter+=1
IF NOT %2=="empty" %WAmain:~1,-1%
if %errorlevel%==0 goto :WASuccess

:WAerrorMsg
IF NOT %3=="empty" echo ERROR in %WAerror:~1,-1% Trying again......
if %WAcounter% equ 10 goto :Finish 
goto :WAmainCommand

:WASuccess
IF NOT %4=="empty" %WAaction:~1,-1%
exit

:Finish
exit 

:Error
echo there must be 4 command line arguments
exit
pause

首次调用template.bat时for命令调用if %errorlevel==0%然后退出 来自:WASuccess,如果不是:Finish

未调用第二次模板或未执行其他命令。

请告诉我是否退出第一个命令,如何继续进行第二次模板调用。

由于

1 个答案:

答案 0 :(得分:1)

您应该使用start代替call,或使用来自被叫批次的exit /Bgoto :eof。请参阅this for reference