如果你这样打, 可能会导致执行阻塞
private static void printInput(Process p) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); }
所以,你要用非阻塞的方式来打。CXF源代码里有个不错的例子:
if (p.getErrorStream() != null) { StreamPrinter errorStreamPrinter = new StreamPrinter(p.getErrorStream(), "", System.out); errorStreamPrinter.start(); //StreamPrinter是一个线程 } if (p.getInputStream() != null) { StreamPrinter infoStreamPrinter = new StreamPrinter(p.getInputStream(), "[INFO]", System.out); infoStreamPrinter.start(); //StreamPrinter是一个线程 }