我正在尝试使用Process Builder运行批处理文件,批处理文件位于另一个目录中
String filepath = "D:";
String filename = "hello.bat";
try {
ProcessBuilder p = new ProcessBuilder();
p.directory(new File(filepath));
p.command("cmd.exe", "/c ", filename);
Process process = p.start();
process.waitFor();
InputStream in = process.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = -1;
while((c = in.read()) != -1)
{
baos.write(c);
}
String response = new String(baos.toByteArray());
System.out.println("Response From Exe : "+response);
没有抛出任何异常,似乎它陷入了Process process = p.start();无限期。另外,批处理文件本身没有被执行,这可能是什么问题? [我试过Runtime #exec和桌面#打开,无济于事]
这个概念将类似于:Spring boot application.properties conflict when one application deploys another
在那里,我提供了一套完整的代码。