How to not exit from a called batch file

时间:2016-02-12 19:29:48

标签: java windows batch-file cmd

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:

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.

How can I keep the internal batch alive after the external batch finishes its job?

1 个答案:

答案 0 :(得分:1)

如果您只是希望用户能够通过在命令窗口中手动输入来附加fileWithCommandsForBatch的标准输入,请参阅"Prepend to stdin"。 (您的Java程序不会涉及。)在外部批处理中,您可能会获得类似

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

我想,如果重定向按预期工作(具体的输入是逐行而不是单击键),它在某种程度上取决于被调用的anotherBatch.bat。请注意more期望用户输入行,因此省略原始脚本的pause。如果没有被调用anotherBatch.bat处理,用户可以通过发送EOF终止输入(通过在命令窗口中键入F6或Control-Z)。