如何在下面的程序中发送两个以上的参数?请咨询
ProcessBuilder pb = new ProcessBuilder("/bin/bash", scriptPath + script, "myArg1", "myArg2");
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.put("VAR2", env.get("VAR1") + "suffix");
try {
Process p = pb.start();
p.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
您可以向地图添加其他值:
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.put("VAR2", env.get("VAR1") + "suffix");
env.put("VAR3", "one more");
或者你可以在构造函数中添加另一个参数,因为它需要var args:
ProcessBuilder pb = new ProcessBuilder("/bin/bash",
scriptPath + script, "myArg1", "myArg2", "myArg3");