0
我試圖使用ProcessBuilder
在CMD.EXE啓動應用程序,等待它完成,然後將其關閉。到目前爲止,我嘗試過:打開和關閉應用從Java
String[] cmdline=new Stirng{}("cmd.exe","/C","start",application_and_parameters);
ProcessBuilder processBuilder = new ProcessBuilder(cmdline);
Process p = processBuilder.start();
//get error and input streams
int exitVal = p.waitFor();
它按預期打開窗口,但未關閉。我想:
p.destroy()
併發送退出命令:
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
writer.write("exit");
writer.flush();
但沒有成功,CMD住宿。任何人都可以提出解決方案
試試這個:HTTP:/ /stackoverflow.com/questions/3468987/executing-another-application-from-java –