LinuxにJavaでシエルコマンドを実行する方法

方法1
Runtime.getRuntime().exec(sampleShellScript);

方法2
ProcessBuilder pb = new ProcessBuilder(“sampleShellScript.sh", “sampleArg1", “sampleArg2");
Map<String, String> env = pb.environment();
env.put(“Var1", “sampleValue");
env.remove(“OtherVar");
env.put(“Var2", env.get(“Var1") + “suffix");
pb.directory(new File(“sampleDir"));
Process p = pb.start();

Java

Posted by arkgame