从嵌套批处理文件退出 [英] Exit from nested batch file

查看:73
本文介绍了从嵌套批处理文件退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个批处理文件,假设a.bat,b.bat,c.bat和d.bat.现在,这些批处理文件的调用方式是a.bat调用b.bat,b.bat调用c.call等.

I have 4 batch files, suppose a.bat, b.bat, c.bat and d.bat. Now these batch files are called in such a manner that a.bat calls b.bat, b.bat calls c.call and so on.

如果在任何批处理文件中出现任何错误,我想退出整个程序,方法是说发生了错误,并提及哪个批处理文件有问题.我的问题是,我该怎么办?

If I get any error in any batch file, I want to exit from the entire program by saying an error occurred, and mention which batch file had a problem. My question is, how can I do this?

在这里,我使用了 exit/b ,但是它仅从当前的批处理文件中退出,并从被称为的地方移回到批处理文件中:

Here I used exit /b but it only gets out from the current batch file and moves back into batch file from whence it was called:

@echo. off
echo. this is batch 'a'
call b.bat

b.bat

@echo. off
echo. this is batch 'b'
call c.bat

c.bat

@echo. off
echo. this is batch 'c'

我在批次'C'中遇到错误-它应该报告一个错误并退出,但是它以某种方式又移回到了批次'B'中.关于如何从嵌套批处理文件退出的任何想法吗?

I get an error in batch 'C' - It should then report an error and exit, but it's moving back into batch 'B' somehow. Any idea on how to exit from a nested batch file?

推荐答案

您可以使用语法错误,这将立即停止批处理而不关闭命令窗口.

You can use a syntax error, this stop immediately the batch without closing the command window.

:HALT 函数调用:__ halt 函数只是为了阻止错误消息.

The :HALT functions calls the :__halt function only to supress the error message.

c.bat

@echo off
echo this is batch 'c'
echo An error occurs
call :HALT
exit /b

:HALT
call :__halt 2> nul
exit /b

:__halt
()

这篇关于从嵌套批处理文件退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆