Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GUI does not pop up in child process before parent is killed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post the same question to multiple forums: CarefullyChooseOneForum

Let's continue the discussion in this duplicate thread.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic