JAVA调用linux中的shell命令行的工具类

来源:互联网 发布:大数据行业 投融资 编辑:程序博客网 时间:2024/06/05 17:05

二话不说,直接上代码!


package cn.sigangjun.util;/** * <p>Title:java call linux shell util </p> * <p>Description: java call linux shell util</p> * @since 2013-8-12 下午3:50:15  * @version 1.0 * @author <a style='color:red' href='http://blog.csdn.net/sigangjun'>sigangjun</a> */public class JavaShellUtil {public static int executeShell(String shellCommand) {  int success = 0;  try {   String[] cmd = {"/bin/sh", "-c", shellCommand};   Process pid = Runtime.getRuntime().exec(cmd);   if (pid == null) {   success = 1; }} catch (Exception e) {  e.printStackTrace();success = 1;} return success;  }  }



原创粉丝点击