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?


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

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

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

Consider using commons-exec when dealing with external processes. In my opinion it is much easier to handle than using the Java Runtime class.

Tutorial :

Run your command from a JDialog and after running it, use toBack().

final JDialog dlg = new javax.swing.JDialog(null, "test", JDialog.ModalityType.DOCUMENT_MODAL);
JButton button = new JButton("Select Me");
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        try {
        } catch (IOException e1) {
            throw new RuntimeException(e1);

Need Your Help

saxon transform xml with url parameters

xml xslt saxon

I got an xhtml file containing links with multiple parameters :

how to filter repeated rows using DATE in Mysql

mysql join left-join

i have 4 tables and i am using LEFT JOIN to merge the tables and all work fine.