98.7. 用法示例
98.7.1. 执行字数(Linux)
以下示例执行 wc (字数,Linux)来计算文件 /usr/share/dict/words 中的词语。字数(输出)被写入 wc 的标准输出流。
from("direct:exec")
.to("exec:wc?args=--words /usr/share/dict/words")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
// By default, the body is ExecResult instance
assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody());
// Use the Camel Exec String type converter to convert the ExecResult to String
// In this case, the stdout is considered as output
String wordCountOutput = exchange.getIn().getBody(String.class);
// do something with the word count
}
});