java调用批处理(doc)执行多条命令

时间:2022-09-02 23:52:52
String CurPaths = System.getProperty("user.dir");
String CurPath = CurPaths+"\\jdk1.7.0_67\\bin;";
String Paths = System.getProperty("java.library.path"); 
System.out.println("Paths=="+Paths);
String Path = CurPath+Paths; 
// System.setProperty("java.library.path",Path);
System.out.println("Path=="+Path);
try {

String pathlast = "cmd /c set Path="+Path+ " && cmd /c start javaw -jar "+CurPaths+"/trggrrr.jar";

//批处理doc命令在java调用多条命令执行的时候需要用&&来连接起来,命令在项目中正常使用,没有问题

Runtime.getRuntime().exec(pathlast);
// Process process = Runtime.getRuntime().exec("cmd /c set Path="+Path );
// Runtime.getRuntime().exec("cmd /c start javaw -jar "+CurPaths+"/trggrrr.jar");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();


}