Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package net.mamian.mySpringboot.utils; import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; /** * shell * * @author mamian * @mail mamianskyma@aliyun.com * @date 2016-12-24 9:45:39 * @copyright 2016 ? All Rights Reserved * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ @Slf4j public class ShellUtils { /** * * * @param shPath shell * @param param ? * @return */ public static int exe(String shPath, String... param) { if (StringUtils.isEmpty(shPath)) { log.info("shell?shpath={}", shPath); return -1; } Process p; try { shPath = "chmod 755 " + shPath; if (null != param) { for (String paramItem : param) { shPath += " " + paramItem; } } log.info("shellshpath={}", shPath); p = Runtime.getRuntime().exec(shPath); p.waitFor(); log.info("shellshpath={}", shPath); } catch (IOException | InterruptedException ex) { log.info("shellshpath={} exception={}", shPath, ex); return -1; } return 0; } }