怎样在java代码中调用执行shell脚本

 // 用法:Runtime.getRuntime().exec("命令");
     
    String shpath="/test/test.sh";   //程序路径
    Process process =null;
    String command1 = “chmod 777 ” + shpath;
    try { 
      Runtime.getRuntime().exec(command1 ).waitFor(); 
    } catch (IOException e1) { 
        e1.printStackTrace(); 
    }catch (InterruptedException e) { 
         e.printStackTrace(); 
    }
 
 
    String var="201102";  /参数

 

posted on 2016-10-26 17:40  让编程成为一种习惯  阅读(1727)  评论(0编辑  收藏  举报