반응형
command 창에서만 실행하던 배치 혹은 쉘스크립트 파일을 자바에서 실행해야할 일이 생겨 아래와 같이 작성하였다.
result값이 0이면 실행 성공한 것!
public boolean runXXXX(String xxxx) {
boolean result = false;
String filePath = "파일 path";
super.logger.debug("file path : " + filePath);
File file = new File(filePath);
try {
if(file.exists()){
CommandLine cmdLine = CommandLine.parse(filePath+" "+req_id);
DefaultExecutor executor = new DefaultExecutor();
try {
int batch_result = executor.execute(cmdLine);
if(batch_result == 0){
result = true;
}else{
result = false;
super.logger.error("The batch program failed to run.");
return result;
}
} catch (ExecuteException e) {
super.logger.error(PrintStackTraceUtils.getErrStrFromException(e));
result = false;
return result;
} catch (IOException e) {
super.logger.error(PrintStackTraceUtils.getErrStrFromException(e));
result = false;
return result;
}
}else{
super.logger.error("File not found : " + filePath);
result = false;
return result;
}
} catch (Exception e) {
super.logger.error(e.getMessage());
result = false;
}
return result;
}
728x90
반응형
'개발 > JAVA' 카테고리의 다른 글
[JAVA] 직렬화(Serialized), 역직렬화(Deserialization) (0) | 2025.02.03 |
---|---|
[JAVA] 접근제한자가 private인 메소드를 호출하는 방법 (1) | 2022.10.13 |
[JAVA] KeyStore에 Root 인증서 등록하기(SSLHandshakeException, PKIXException) (1) | 2022.05.18 |
[JAVA] Runnable 과 Thread의 차이 (0) | 2022.05.16 |
[JAVA] 비동기 처리 방법 - Thread (0) | 2022.04.27 |
댓글