Java执行Shell脚本

版权声明:学习交流为主,未经博主同意禁止转载,禁止用于商用。 https://blog.csdn.net/u012965373/article/details/82973129
String[] cmd = new String[]{"sh", "-c", shell命令};
System.out.println(cmd.toString());
Process process = null;
try {
    process = Runtime.getRuntime().exec(cmd);
    //必须等待该进程结束,否则时间设置就无法生效
    process.waitFor();
} catch (Exception error) {
    error.printStackTrace();
    LOG.error(error.getMessage());
}finally{
    if(process!=null){
        process.destroy();
    }
}

猜你喜欢

转载自blog.csdn.net/u012965373/article/details/82973129