写入输出和使用 PumpStreamHandler 记录文件时出错
我一直在寻找一个编写流程输出和流程输出的好例子。错误流到日志文件。 我使用 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);
}
I have been searching for a while to get a good example for writing Process output & error stream to log file.
I use apache-commons exec library to execute my process. Following a code sample to demonstrate that
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是实现此目的的代码。
这就是我们如何使用上面的类。
像这样使用 apache-commons exec 可以使代码 & (程序员的)生活就是这么简单。我能够丢弃大量使用 Runtime.exec 执行命令行命令的代码。
Following is the code to achieve this.
This is how we can use the above class.
Using apache-commons exec like this makes code & life (of a programmer) so simple. I was able to discard a huge amount of code that used Runtime.exec to execute commandline commands.