title: Runtime.exec().waitFor() doesn't wait until process is done
body: <p>I have this code:</p>
  
  <pre><code>File file = new File(path + "\\RunFromCode.bat");
  file.createNewFile();
  
  PrintWriter writer = new PrintWriter(file, "UTF-8");
  for (int i = 0; i &lt;= MAX; i++) {
      writer.println("@cd " + i);
      writer.println(NATIVE SYSTEM COMMANDS);
      // more things
  }
  
  writer.close();
  
  Process p = Runtime.getRuntime().exec("cmd /c start " + path + "\\RunFromCode.bat");
  p.waitFor();
  
  file.delete();
  </code></pre>
  
  <p>What happens is that the file deleted before it actually executed.</p>
  
  <p>Is this because the <code>.bat</code> file contains only native system call? How can I make the deletion <strong>after</strong> the execution of the <code>.bat</code> file? (I don't know what the output of the <code>.bat</code> file will be, since it dynamically changes).</p>