0

我在执行 .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();
    }
}

4

0 回答 0