2010-06-02 97 views
0

我有一个批处理文件,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 

当第一次调用该for命令template.bat调用if %errorlevel==0%然后退出从:WASuccess ,如果不是它退出:Finish

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

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

感谢

+0

为了便于阅读,您可以编辑您的文章并制作代码部分lokk liek代码? – Thariama 2010-06-02 11:33:47

+0

请注意,您可以使用'%〜1'等自动剥离引用,这将使该批的其余部分更易于阅读。 – Joey 2010-06-11 01:14:22

回答

1

您应该使用任start代替call,或使用exit /Bgoto :eof从称为批处理。请参阅this for reference

+0

'exit/b'或'goto:eof'的好处。不过,关于'start'的部分是无稽之谈,除非他们想异步运行'template.bat'。 – Joey 2010-06-11 01:13:52