Run an external application from java - and DO NOT bind it to a virtual machine

Sometimes my large Java application needs to run an external program. I can do this quite easily with Runtime.getRuntime (). Exec ("application name");

The problem is that the running application seems to be related to my Java process as it terminates when my Java application exits. I want to keep another application.

Edit: Made a mistake with the above description. The launched application is NOT terminated.

The problem is that after my original application exits, I cannot start it again. UNTIL the running application ends. The original application (and the running application) are the Launch4J generated .exe files.

So how can I get the running application to prevent the original application from exiting completely?

(Oh, and just to throw another monkey at it, the running app uses a 32-bit JVM, and the original app runs on a 64-bit JVM.)

+3


source to share


2 answers


While the shell command trick might work, I found an easier way.

Desktop.getDesktop (). open ("application name");



Obviously, it launches the application in such a way that it is not tied to the original program.

+2


source


One way that should work is to run a shell command that starts your program as an independent process.

For example on Linux (based on this answer ):

Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", "nohup app_name &"});

      



An on Windows:

Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "start app_name"});

      

0


source







All Articles