0

I've been working on in a swing application. I've a JFrame having some buttons and fields.

On some button click event,I'm opening an exe from my current directory. Everything works fine.

try {
      Runtime.getRuntime().exec(System.getProperty("user.dir") +
      "\\Upgrade\\Upgrade.exe");
      } catch (IOException ex) {
       ex.printStacktrace();
        }
   this.dispose(); // disposing my current java file.

But what i need is to exit the java code after opening the exe file.

Anyone help to deal this.?

SanCJ
  • 61
  • 1
  • 8

2 Answers2

0

Can you try making it a process, then waiting for that process to finish before exiting, like so:

class SO {
public static void main(String args[]) {
try {
    Process proc = Runtime.getRuntime().exec("your command");
    proc.waitFor(); //Wait for it to finish
    System.exit(0);
} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}
}
}
Levenal
  • 3,796
  • 3
  • 24
  • 29
  • @SanCJ Glad it works, when you can the chance may I please have a green tick to show the questions as having an accepted answer =D – Levenal Nov 21 '13 at 11:56
0

Executing an application from java using Runtime.exec() is a source of well known problems. Like waiting for a Process to finish, but not consuming the data from the stream buffers is a sure way for you application to hang.

I would suggest you use a library like Apache Common Exec to handle this.

I worked on a project a while back where we used Runtime.exec() to launch a process that would eventually extract files over existing files. All worked well except on one machine used for staging - it would just hang. It turned out on that staging machine, someone had set the date/time back so it looked liked the new files being extracted where older than the existing one, causing the external process to generate a warning message for each, overflowing the error buffer - which our application was not consuming!

Simon Arsenault
  • 1,241
  • 11
  • 12