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

本文介绍如何在Java中通过设置系统属性和执行批处理命令来实现环境变量的配置,包括路径和环境变量的修改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值