Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 427
user15683854875644328975643872 Avatar asked Aug 16 '12 09:08

user15683854875644328975643872


Video Answer


2 Answers

Process#waitFor() is what you're looking for.

like image 57
yegor256 Avatar answered Sep 20 '22 00:09

yegor256


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

Process pr = rt.exec("cmd.exe /c start");
like image 20
Aleksandr Nikiforov Avatar answered Sep 20 '22 00:09

Aleksandr Nikiforov