Java Run Shell Script

来源:互联网 发布:只有我知大结局 编辑:程序博客网 时间:2024/05/18 12:35
private int runShellScript(String strShellScript) {        try {            LOGGER.info("Ready to run {}", strShellScript);            Process process = Runtime.getRuntime().exec(strShellScript);            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));            String line = "";            while ((line = input.readLine()) != null) {                LOGGER.info(line);            }            input.close();            int exitValue = process.waitFor();            if (0 != exitValue) {                LOGGER.error("call shell failed, error code is {}", exitValue);            }            return exitValue;        } catch (Throwable e) {            LOGGER.error("call shell failed {}", e);            return -1;        }    }
原创粉丝点击