简体   繁体   中英

How do I get the information of a batch script started in java, whether it has already ended

im calling multiple batch files in Java with the ProcessBuilder like

ProcessBuilder processBuilder = new ProcessBuilder("cmd", "/c", "Start", "batchTest.bat"); 
File dir = new File(path);
processBuilder.directory(dir);
try {
    Process p = pb.start();
} catch (IOException e) {
// TODO Auto-generated catch block
    e.printStackTrace();
}

Now i want the information that the script is done in java. Like just a sysout when the script is completly finished. process.isAlive() turns false before the script is done. And also process.witFor() doesnt get the job done. Maybe someone has an idea or a workaround?

Okay, i got it. process.waitFor() only works if you add the parameter "/wait" to the Constructor of the ProcessBuilder.

new ProcessBuilder("cmd", "/c", "Start", "/wait", "batchTest.bat");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM