2012年2月21日星期二

How to run Unix shell script from java code? - Stack Overflow

How to run Unix shell script from java code? - Stack Overflow

You should really look at Process Builder. It is really built for this kind of thing.

ProcessBuilder pb = new ProcessBuilder("myshellScript.sh", "myArg1", "myArg2");  Map env = pb.environment();  env.put("VAR1", "myValue");  env.remove("OTHERVAR");  env.put("VAR2", env.get("VAR1") + "suffix");  pb.directory(new File("myDir"));  Process p = pb.start(); 

没有评论: