简体   繁体   English

批处理脚本在异常情况下暂停,可以自动继续吗?

[英]Batch script pauses on exception, possible to continue automatically?

I have the following snippet in a batch file to run a program with an argument in a loop: 我在批处理文件中有以下代码段,以在循环中运行带有参数的程序:

for /F "tokens=*" %%a in (some-list.txt) do (
    java -jar some-java-package.jar com.example.package.class %%a
)

Sometimes the Java application crashes on a memory exception (this could be an important point, because according to my current programming experience these seem to be special exceptions and I was not able to catch them like I would catch normal exceptions in program code). 有时Java应用程序会因内存异常而崩溃(这很重要,因为根据我目前的编程经验,这些似乎是特殊的异常,并且我无法像在程序代码中捕获普通异常那样捕获它们)。

In such a case it seems my batch script pauses until I take action: I can press Ctrl-C and on batch's question if I want to stop the batch job respond N , then it will continue with the next program call. 在这种情况下,似乎我的批处理脚本会暂停,直到我采取措施为止:我可以按Ctrl-C并在批处理的问题上是否要停止批处理作业,响应N ,然后它将继续下一个程序调用。

Is it possible to tell batch to go on in such events automatically? 是否可以告诉批处理在此类事件中自动进行?

You should call java using the start command like this: 您应该使用以下start命令调用java

for /F "tokens=*" %%a in (some-list.txt) do (
    start "" /WAIT "java" -jar some-java-package.jar com.example.package.class %%a
)

The /WAIT switch lets start wait until the application ( java ) has finished execution. 通过/WAIT开关,可以start等待,直到应用程序( java )完成执行。
The "" portion defines the window title (this is defined here since start sometimes confuses it with the command line when no title given). ""部分定义了窗口标题(在此定义,因为在没有给出标题的情况下, start有时会使它与命令行混淆)。

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

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