๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/JAVA

[JAVA] ๋ฐฐ์น˜(bat), ์‰˜(sh) ์‹คํ–‰ํ•˜๊ธฐ

by ynzu๐Ÿค 2022. 5. 18.
๋ฐ˜์‘ํ˜•

 

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
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€