gpt4 book ai didi

java - 使用java依次执行多个批处理文件

转载 作者:太空宇宙 更新时间:2023-11-04 10:35:40 25 4
gpt4 key购买 nike

我想在我的java应用程序中依次执行同一个批处理文件。我想等到批处理文件完成,然后执行下一个。我正在使用运行时,然后 waitFor 但它不起作用。

请帮助我。

最佳答案

您好,尝试使用以下代码,它将解决您的问题:-

String[] command ={"/pathto/your/batch.sh", "commandLineParameter"};
//for example if you run your batch manually like 'mybatch.sh today'
// so your command line parameter is today
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectOutput(new File("/tmp/output.txt"));
//in the above output.txt you can see the output from the command
while(true){
try {
Process p = pb.start();
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}catch (Exception e1) {
e1.printStackTrace();
}
if(something)//put your condition here when to break the loop
break;
}//end of while loop

关于java - 使用java依次执行多个批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49510168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com