2 回答
TA贡献2003条经验 获得超2个赞
在单独的线程中处理进程的输出流可能会有所帮助。您还想明确地等待该过程结束,然后再继续执行逻辑操作:
ProcessBuilder builder = new ProcessBuilder("java",
textFieldMemory.getText(), "-jar", myJar);
final Process process = builder.start();
final Thread ioThread = new Thread() {
@Override
public void run() {
try {
final BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (final Exception e) {
e.printStackTrace();
}
}
};
ioThread.start();
process.waitFor();
添加回答
举报