java Process执行linux命令

public static int transfrom (String id){

Process process =null;

//pro1等语句自定义自己要执行的语句用&&符号连接 按照先后顺序执行    /bin/sh  -c 是不变的

String[] command1 = new String[]{
"/bin/sh","-c",pro1+" && "+pro2+" && "+pro3+" && "+delete1+"&&"+delete2+" && "+delete3+" && "+delete4
};


try {
process = Runtime.getRuntime().exec(command1);
process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 100;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 100;
}

return 0;

}

原文地址:https://www.cnblogs.com/fengyifengceaser/p/7366109.html