2014-10-08 135 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