日期:2014-05-16  浏览次数:20703 次

执行Linux或者Window命令
执行Linux或者Window下的命令的代码:
public static void runbat(String batFilePath) {
      if(System.getProperty("os.name").toUpperCase().contains("WIN")){
             //不做任何处理
      }else{
             batFilePath="sh "+batFilePath;
      }
      try {
             Process ps = Runtime.getRuntime().exec(batFilePath);
             InputStream is = ps.getInputStream();
             int c;
      while ((c = is.read()) != -1) {
           // System.out.println("执行成功 " + c);
      }
            is.close();
      } catch (Exception e) {
            e.printStackTrace();
      }
}