从批处理文件返回控制权

发布于 2024-12-21 15:49:35 字数 255 浏览 2 评论 0原文

我有一个批处理文件,其中包含以下几个命令;

XCOPY 
DEL 
RMDIR

anotherBatch.bat

XCOPY 
DEL 
RMDIR

正如您所看到的,在这之间有一个对另一个批处理文件(anotherBatch.bat)的调用,它执行一些其他处理。

现在我的问题是,执行 anotherBatch 后,控件永远不会返回到原始批处理文件,并且只是在那里结束。

如何确保控制权返回?

I have a batch file which has several commands as follows;

XCOPY 
DEL 
RMDIR

anotherBatch.bat

XCOPY 
DEL 
RMDIR

As you can see, in between there is a call to another batch file (anotherBatch.bat), which does some other processing.

Now my question is after anotherBatch gets executed, the control never returns back to the original batch file and it just ends there.

How do I make sure that the control is returned back ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2024-12-28 15:49:35

批处理 SUBROUTINE 是通过 CALL 命令调用的另一个批处理文件:

CALL subroutineName Param1 Param2

子例程可以放置在调用代码的同一文件中。这是通过在其名称前加上冒号来指示的:

CALL :SubroutineInThisFile Param1 Param2
. . . .
. . . .
. . . .
EXIT /B

:SubroutineInThisFile
. . .
EXIT /B

:AnotherSubroutine
. . .
EXIT /B

EXIT /B 命令(不仅仅是 EXIT)用于在同一文件中标记子例程结束;主程序也必须这样做。

如果在没有 CALL 命令的情况下调用另一个批处理文件(如您的示例中所示),则最终结果类似于“转到另一个文件”:当调用的文件结束时,进程将在该点结束。我曾经将这样的批处理文件称为“覆盖”(而不是“子例程”)。

A Batch SUBROUTINE is another Batch file called via CALL command:

CALL subroutineName Param1 Param2

The subroutine may be placed in the same file of the calling code. This is indicated by preceding its name with colon:

CALL :SubroutineInThisFile Param1 Param2
. . . .
. . . .
. . . .
EXIT /B

:SubroutineInThisFile
. . .
EXIT /B

:AnotherSubroutine
. . .
EXIT /B

The EXIT /B command (NOT just EXIT) is used to mark the subroutine end in the same file; this must also be done for the main program.

If another Batch file is invoked with no CALL command, as in your example, the net result is similar to a "GOTO to another file": when the invoked file ends, the process ends at that point. I used to call "Overlay" (instead of "subroutine") a Batch file called this way.

半步萧音过轻尘 2024-12-28 15:49:35

您应该显式调用另一个批处理文件

call anotherBatch.bat

you should explicitly call the other batch file

call anotherBatch.bat
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文