Web/웹 상식
Java에서 외부 프로세스 실행하기
MarrRang
2021. 4. 7. 00:09
Apache Commons Exec 이용
1) dependency 추가
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>
2) 실행 예시
public void execute(String[] command)
throws IOException,InterruptedException {
DefaultExecutor executor = new DefaultExecutor();
CommandLine cmdLine = CommandLine.parse(command[0]);
for (int i=1, n=command.length ; i<n ; i++ ) {
cmdLine.addArgument(command[i]);
}
executor.execute(cmdLine);
}
반응형