我正在从 Java 运行 wkhtmltopdf。我创建了一个进程,但这个进程似乎挂起,因为它在控制台上一次又一次地重复,也在任务管理器中。
这就是我运行 wkhtmltopdf 的方式:
String command = applicationLocation + "wkhtmltopdf.exe -O Landscape " + reqURL + "?" + reqQuery + " c:/PDF/" + folderName + "/" + id + "/" + folderName + ".pdf";
Process p = Runtime.getRuntime().exec(command);
工作完成后,我怎样才能“破坏”这个过程?
这对我不起作用,进程从未停止,代码也从未进入 while 循环:
ProcessBuilder pb = new ProcessBuilder(application, htmlFilePath, pdfFilePath);
Process process = pb.start();
BufferedReader errStreamReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
System.out.println("read errstreamreader");
//not "process.getInputStream()"
String line = null;
line = errStreamReader.readLine();
while(line != null) {
System.out.println(line);
line = errStreamReader.readLine();
if(line.equals("Done")) {
process.destroy();
System.out.println("destroyed process");
}
}