[英]close batch file after execution in java
I am trying to create a bat file and running it. 我正在尝试创建一个bat文件并运行它。 Once execution is complete, bat file should close.
执行完成后,bat文件应关闭。
String cmd = "cmd /c start" + " "+"java -jar batchfilepath"+" "+"\n exit";
Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmd);
Issue- I am able to close the bat file but it closes before execution completes. 问题-我可以关闭bat文件,但是在执行完成之前将其关闭。
I tried following ways 我尝试了以下方法
1.if(p.waitfor()==0)
{rt.exec("taskkill /IM cmd.exe");}
2.cmd /c start \wait
3.cmd /k start \wait
4.processBuilder
Help me on this. 帮助我。
add /wait to wait for the entire execution to complete and then close the batch file. 添加/ wait以等待整个执行完成,然后关闭批处理文件。
Try this. 尝试这个。 Hope this works
希望这行得通
cmd /c start" + " "+"/wait"+" cmd / c start“ +”“ +” / wait“ +”
This worked for me with a java.jar file in windows. 这对我在Windows中的java.jar文件有用。
The batch file: 批处理文件:
@echo off
cd C:\NetbeansProject\
java -jar MP2ways.jar
End of the program after data displayed, added: 显示数据后程序结束,添加:
System.out.println("\n Hit Return to exit... ");
String kS = scan.nextLine();
System.exit(0);
Window closes when hitting return. 点击返回时,窗口关闭。 (for what it's worth, which ain't much``)
(对于它的价值,那不多'')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.