问题描述
但是这个问题只出现在那个文件上,在许多其他文件中 - 一切正常
命令看起来像:
rar x /tmp/junit15696402387580789438/ОС.rar /tmp/junit15696402387580789438
案例:
Process process = new ProcessBuilder(commandarray).start();
try (Reader reader = new InputStreamReader(process.getInputStream())) {
CharStreams.toString(reader);
} catch (Exception e) {
getLogger().error(e);
}
return process.waitFor();
返回0代码,好的
但是如果我只是替换getInputStream和waitFor,它将永远执行
代码:
Process process = new ProcessBuilder(commandarray).start();
int code = process.waitFor();
try (Reader reader = new InputStreamReader(process.getInputStream())) {
CharStreams.toString(reader);
} catch (Exception e) {
getLogger().error(e);
}
return code;
在方法 process.waitFor()
中,它将永远循环
我设置了 Thread.sleep(100000)
,但没有帮助
Process process = new ProcessBuilder(commandarray).start();
try {
Thread.sleep(100000);
} catch (InterruptedException e) {
e.printstacktrace();
}
int code = process.waitFor();
try (Reader reader = new InputStreamReader(process.getInputStream())) {
CharStreams.toString(reader);
} catch (Exception e) {
getLogger().error(e);
}
return code;
该过程花费的时间很少,在命令行中只需 1-2 秒
所以:
-
这是正常情况吗,我必须先对进程做一些事情才能获得退出代码?我想,该进程必须在其他线程中执行,我不需要拉任何其他方法? 为什么会发生?为什么 Process 命令 waitFor() 可以在不调用 getInputStream() 的情况下永远执行?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)