Hi!
I have an application that launches other java apllications, each of them its own JVM. Fo that I use ProcessBuilder. Fore each application to be launched, the Main application creates a thread like this:
Thread t = new Thread(new Runnable() {
public void run() {
try {
runApp(StartupHelper.PUZZLE);
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.start();
where runApp() looks like this:
public static void runApp(String filename) {
File directory = createWorkingDirectory(filename);
String args[] = { directory.getAbsolutePath() + "/" + filename };
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(directory);
Process process;
try {
process = pb.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
In that code, filename is the name of a .bat file that executes java.exe (among other things).
If the application being launched does not have a GUI, then everything works as expected. However, if it has a GUI, then I can see that a java.exe process is created, but the GUI does not pop up. For the GUI to pop up I have to kill the Main application. The problem is that sometimes, if I killed the Main application, the lanched application also dies. I am getting crazy with this behavior, so I would appreciate any help.
Also, if after invoking pb.start() I do not get and print the output of the just created process, the process dies. Is that normal?
Thanks a lot!
Cheers,
Nicolás