Search code examples
javaprocessforeground

Java, run another application in foreground


I want run another application from java code.

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd.exe");

Process is launched, but in background. How to make it run in foreground?


Solution

  • You should tell cmd.exe that you want it to open in new window:

    Process pr = rt.exec("cmd.exe /c start");