简体   繁体   English

如何不退出已调用的批处理文件

[英]How to not exit from a called batch file

I am writing a batch file which calls another batch file. 我正在编写一个调用另一个批处理文件的批处理文件。 The external batch is mine, the internal isn't. 外部批次是我的,内部批次不是。

The external batch is called from Java application: 从Java应用程序调用外部批处理:

Runtime.getRuntime().exec("cmd /c start " + batchFileName, null, new File(batchFileDir));

The internal batch is called from the external batch: 从外部批次调用内部批次:

call C:\anotherBatch.bat <fileWithCommandsForBatch
pause

The problem is that the internal batch finishes when the external batch finishes. 问题是内部批处理在外部批处理完成时完成。 I want that the user will still be able to run commands of its own on the internal batch. 我希望用户仍然可以在内部批处理上运行自己的命令。

If I run the same commands of "fileWithCommandsForBatch" manually from cmd, the internal batch is still alive. 如果我从cmd手动运行“ fileWithCommandsForBatch”的相同命令,则内部批处理仍然有效。

How can I keep the internal batch alive after the external batch finishes its job? 外部批处理完成工作后,如何使内部批处理保持活动状态?

If you just want users to be able to append to the standard input from fileWithCommandsForBatch by manually typing within the command window, see "Prepend to stdin" . 如果只希望用户能够通过在命令窗口中手动键入来从fileWithCommandsForBatch追加到标准输入,请参阅“ Prepend to stdin” (Your Java program would not be involved.) In your external batch, you might get code like (您的Java程序将不会涉及。)在您的外部批处理中,您可能会获得类似以下的代码

(
type fileWithCommandsForBatch
more
) | call C:\anotherBatch.bat

I guess, it somewhat depends on the called anotherBatch.bat if redirection works as intended (specifically input is line-by-line not single keystrokes). 我猜想,如果重定向按预期进行,则在某种程度上取决于被称为anotherBatch.bat (具体而言,输入是逐行而不是单个按键)。 Note that more expects users to type lines, so the pause of your original script is omitted. 请注意, more用户希望用户键入行,因此省略了原始脚本的pause If not handled by called anotherBatch.bat , users can terminate input by sending an EOF (by typing F6 or Control-Z in command window). 如果未通过调用anotherBatch.bat处理,则用户可以通过发送EOF(在命令窗口中键入F6或Control-Z)来终止输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM