java Runtime如何执行多条命令
使用 && 分隔命令
String[] cmds = {"/bin/sh", "-c", " 第一条命令 && 第二条命令"};
Process pro = Runtime.getRuntime().exec(cmds);
pro.waitFor();
InputStream in = pro.getInputStream();
BufferedReader read = new BufferedReader(new InputStreamReader(in));
String line = null;
while ((line = read.readLine()) != null) {
System.out.println(line);
}
操作linux系统使用"/bin/sh", "-c"
操作windows系统使用"cmd", "/c"