2014-10-08 195 views
1

我有一個批處理腳本調用批處理文件序列。退出調用另一個批處理腳本的批處理腳本

有一個錯誤情況,我需要退出被調用的批處理文件以及父批處理文件。是否有可能在子批處理文件中完成此操作?預先感謝所有提示/幫助。

test.bat的

rem Test1.bat will exit with error code. 
call test1.bat 
rem Want script to stop if test1.bat errors. 
call test2.bat 

test1.bat

rem Can I get test.bat to terminate from inside test1.bat? 
exit /b 1 

回答

1

您可以通過使用錯誤級別。如果被叫批次系統地使用exit 0通知繼續exit 1詢問來電者停下來,你可以修改方法調用者:

rem Test1.bat will exit with error code. 
call test1.bat 
rem Want script to stop if test1.bat errors. 
if errorlevel 1 goto fatal 
call test2.bat 
exit 0 
:fatal 
echo Fatal error 
exit 1 
+0

完美謝謝。 – wheatfairies 2014-10-08 19:11:50