Java,在前台运行另一个应用程序

use*_*872 6 java process foreground

我想从java代码运行另一个应用程序.

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd.exe");
Run Code Online (Sandbox Code Playgroud)

流程已启动,但在后台.如何让它在前台运行?

yeg*_*256 5

Process#waitFor()就是你要找的。


小智 4

您应该告诉 cmd.exe 您希望它在新窗口中打开:

Process pr = rt.exec("cmd.exe /c start");
Run Code Online (Sandbox Code Playgroud)