执行.bat文件时遇到一些问题。 我使用Spring Roo从命令行生成Web服务,并希望通过Java代码将连接器写入.bat文件。 当我启动应用程序时,它挂起了(似乎当前线程正在切换到.bat文件)。 如何配置对roo.bat(或另一个.bat文件)与Java代码之间的命令交换过程的支持。
For example:
--> start roo.bat
--> answer: roo>
--> send from java: project setup --topLevelPackage org.springframework.roo.example
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "C://Users/Documents/roo/bin/roo.bat");
pb.redirectErrorStream(true);
Process proc = pb.start();
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
int exit = -1;
while ((line = br.readLine()) != null) {
// Outputs your process execution
System.out.println(line);
try {
exit = proc.exitValue();
if (exit == 0) {
// Process finished
}
} catch (IllegalThreadStateException t) {
proc.destroy();
}
}