I am trying to execute a Bash Shell script from Java and it runs fine using this piece of code.
public void executeScript() {
try {
new ProcessBuilder("myscript.sh").start();
System.out.println("Script executed successfully");
} catch (IOException e) {
e.printStackTrace();
}
}
The above code runs fine asynchronously. But what I would like to achieve is to execute the code synchronously. I would like the Java process to wait until the execution of the script is completed and then execute the next batch of code.
To summarize, I would like the "Print statement - Script executed successfully" to be executed after the batch file ("myscript.sh") completes execution.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…