I have this code:
File file = new File(path + "\\RunFromCode.bat");
file.createNewFile();
PrintWriter writer = new PrintWriter(file, "UTF-8");
for (int i = 0; i <= 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();
What happens is that the file deleted before it actually executed.
Is this because the .bat
file contains only native system call? How can I make the deletion after the execution of the .bat
file? (I don't know what the output of the .bat
file will be, since it dynamically changes).