我在这里做错了吗?没有正确处理流?
我在这里运行一个流程(特别是:mvn exec:java
),即使我运行p.killForcibly()
,流程也不会终止。
如果我转到命令行并在我从flapdoodle库获取的pid上尝试taskkill /F /PID
,我会被拒绝访问#34;并且这个过程依然存在。
try {
ProcessBuilder builder = new ProcessBuilder(commands);
log.createNewFile();
builder.redirectErrorStream(true);
builder.redirectOutput(Redirect.appendTo(log));
final Process p = builder.directory(dir).start();
Long pid = de.flapdoodle.embed.process.runtime.Processes.processId(p);
System.out.println("pid: " + pid);
class InnerRunner implements Runnable {
public void run() {
try {
int rc = p.waitFor();
if (callback != null)
callback.onComplete(rc);
} catch (InterruptedException ie) {
throw new RuntimeException("process was interuppted", ie);
}
}
}
Thread t = new Thread(new InnerRunner());
return p;
} catch (IOException ioe) {
throw new RuntimeException ("Failed to run process: " + commands + ". Ran it in: " + dir.getAbsolutePath(), ioe);
} catch (Throwable t) {
throw new RuntimeException("err", t);
}
Thread t = new Thread(new InnerRunner());
一条可能的线索:输出日志文件我将流程输出重定向到流程仍然保持打开状态。我无法删除它,直到我在任务管理器中终止该过程。