使用启动命令。它依赖于 Windows,但可以满足您的需要。我读过没有跨平台的方式。
ProcessBuilder pb = new ProcessBuilder("cmd", "/C start /B /belownormal javaws -version");
System.out.println("Before start");
Process start = pb.start();
甚至可以读取输入端错误流。
等待:
ProcessBuilder pb = new ProcessBuilder("cmd", "/C start /B /belownormal /WAIT javaws -sdasd");
System.out.println("Before start");
Process start = pb.start();
start.waitFor();
System.out.println("Done");
对于过早破坏:
ProcessBuilder pb = new ProcessBuilder("cmd", "/C start /B /belownormal /WAIT javaws -sdasd");
System.out.println("Before start");
Process start = pb.start();
start.destroy();
start.waitFor();
System.out.println("Done");