98.7. 사용 예

98.7.1. 단어 수 실행 (Linux)

아래 예제에서는 wc (word count, Linux)를 실행하여 /usr/share/dict/words 파일의 단어를 계산합니다. 단어 수(output)는 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
     }
});