title: Opening and closing application from Java
body: <p>I'm trying to use <code>ProcessBuilder</code> to start application in <strong><em>cmd.exe</em></strong>, wait for it to finish and then close it. So far I tried:</p>
  
  <pre><code>String[] cmdline=new Stirng{}("cmd.exe","/C","start",application_and_parameters);
  ProcessBuilder processBuilder = new ProcessBuilder(cmdline);
  Process p = processBuilder.start();
  //get error and input streams
  int exitVal = p.waitFor();
  </code></pre>
  
  <p>It opens window as expected, but doesn't close. I tried:</p>
  
  <pre><code>p.destroy()
  </code></pre>
  
  <p>and to send exit command:</p>
  
  <pre><code>BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
  writer.write("exit");
  writer.flush();
  </code></pre>
  
  <p>but without success, cmd stays. Could anyone suggest a solution?</p>