我正在尝试使用 ProcessBuilder 在 Ubuntu 上获取命令的执行结果。我尝试从以下技术中获取输出结果。但是没有结果显示,程序等待没有输出。
执行命令:
String[] args = new String[]{"/bin/bash", "-c", "pandoc -f html - t asciidoc input.html"};
Process process = new ProcessBuilder(args).start();
获取输出技术1:
InputStream inputStream = process.getInputStream();
StringWriter stringWriter = new StringWriter();
IOUtils.copy(inputStream, stringWriter, "UTF-8");
// Waiting
String asciidocoutput = writer.toString();
获取输出技术2:
BufferedReader reader= new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
// Waiting
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
阿波罗的战车
相关分类