在Java代码中使用Process调用Tomcat startup.bat,这将创建一个新的CMD窗口,而我的Java代码的其余部分将不执行。是否需要启动新的Thread来执行此操作?但即使那样,我仍然无法得到br。
Runtime runtime = Runtime.getRuntime();
Process process;
BufferedReader br = null;
try {
process = runtime.exec(command);
runtime.gc();
String line = null;
String content = "";
br = new BufferedReader(new
InputStreamReader(process.getInputStream()));
while ((line = br.readLine()) != null) {
content += line + "\r\n";
}
System.out.println(content);
} catch (IOException e) {
System.out.println(e);
} finally {
if (br != null) {
br.close();
}
}