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 } });
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
}
});
Copy to clipboardCopied98.7.2. java
실행
아래 예제에서는 java
가 시스템 경로에 있는 경우 -server
및 -version
과 함께 java
를 실행합니다.
from("direct:exec") .to("exec:java?args=-server -version")
from("direct:exec")
.to("exec:java?args=-server -version")
Copy to clipboardCopied
아래 예제에서는 3개의 인수를 사용하여 java
in c:\temp
를 실행합니다. -server
,-version
및 sytem 속성 user.name
.name.
from("direct:exec") .to("exec:c:/program files/jdk/bin/java?args=-server -version -Duser.name=Camel&workingDir=c:/temp")
from("direct:exec")
.to("exec:c:/program files/jdk/bin/java?args=-server -version -Duser.name=Camel&workingDir=c:/temp")
Copy to clipboardCopied98.7.3. ECDHE 스크립트 실행
다음 예제에서는 ant.gradle이 시스템 경로에 있고
을 사용하여 Apache ECDHE(Windows만 해당)을 실행합니다.
CamelExecBuildFile.xml
이 현재 디렉터리에 있는 경우 빌드 파일 CamelExecBuildFile.
xml
from("direct:exec") .to("exec:ant.bat?args=-f CamelExecBuildFile.xml")
from("direct:exec")
.to("exec:ant.bat?args=-f CamelExecBuildFile.xml")
Copy to clipboardCopied
다음 예제에서 ant.
knative 명령은 출력을 -l
을 사용하여 CamelExecOutFile.txt
로 리디렉션합니다. CamelExecOutFile.txt
파일은 outFile=CamelExecOutFile.txt
가 있는 출력 파일로 사용됩니다. 이 예에서는 ant.gradle
이 시스템 경로에 있고 CamelExecBuildFile.xml
이 현재 디렉터리에 있다고 가정합니다.
from("direct:exec") .to("exec:ant.bat?args=-f CamelExecBuildFile.xml -l CamelExecOutFile.txt&outFile=CamelExecOutFile.txt") .process(new Processor() { public void process(Exchange exchange) throws Exception { InputStream outFile = exchange.getIn().getBody(InputStream.class); assertIsInstanceOf(InputStream.class, outFile); // do something with the out file here } });
from("direct:exec")
.to("exec:ant.bat?args=-f CamelExecBuildFile.xml -l CamelExecOutFile.txt&outFile=CamelExecOutFile.txt")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
InputStream outFile = exchange.getIn().getBody(InputStream.class);
assertIsInstanceOf(InputStream.class, outFile);
// do something with the out file here
}
});
Copy to clipboardCopied98.7.4. 에코
실행 (Windows)
echo
및 dir
과 같은 명령은 운영 체제의 명령 인터프리터만 실행할 수 있습니다. 이 예에서는 Windows에서 echo
- 같은 명령을 실행하는 방법을 보여줍니다.
from("direct:exec").to("exec:cmd?args=/C echo echoString")
from("direct:exec").to("exec:cmd?args=/C echo echoString")
Copy to clipboardCopied