我一直在寻找一个很好的例子来将进程输出和错误流写入日志文件。我使用 apache-commons exec 库来执行我的进程。按照代码示例来演示
public static int executeCommand(CommandLine command, Logger log) throws ExecuteException, IOException {
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
PumpStreamHandler psh = new PumpStreamHandler();
executor.setStreamHandler(psh);
return executor.execute(command);
}