I hava a simple Java application which uses the ProcessBuilder and Process classes to execute cmd commands. The commands just load a window. Now the problem is when the window is closed, the process remains running. Below is the code snippet I have used:

        try {
            ProcessBuilder pb = new ProcessBuilder(commands);//command to load a gui app
            Process process = pb.start();
            process.waitFor();
        } 
        catch (IOException ioEx) {
            ioEx.printStackTrace();
        }
        catch (InterruptedException iEx) {
            iEx.printStackTrace();
        }

How do I make the process to stop when the window is closed?

so ... you are calling an external command prompt (not one you've written yourself) and on closing that, you want to end the running of the Java process, am I right?

yes

doubt that's possible. that prompt screen doesn't know what process called/started it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.