java实现dos命令

zings zings 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想用Java实现dos下执行多条命令,想如下这样:

String cmd5 = "net use o: \\10.8.0.90\netfile 123.com/user:administrator";
String cmd6 = "copy o:\\test.txt E:\\share\\cpu.txt"; //cpuinfo.txt
String cmd7 = "net use o: /del";
String cmd8 = "exit";
Runtime.getRuntime().exec("cmd /c start");
// Process process =
Runtime.getRuntime().exec("dir ");
// process.waitFor();
// Process process1 =
Runtime.getRuntime().exec("ipconfig" );
// process1.waitFor();
// Process process2 = Runtime.getRuntime().exec(cmd6);
//// process2.waitFor();
// Process process3 = Runtime.getRuntime().exec(cmd7);
//// process3.waitFor();
// Process process4 = Runtime.getRuntime().exec(cmd8);
// process4.waitFor();
Process process5 = Runtime.getRuntime().exec("exit");
process5.waitFor();
// Process process2 = Runtime.getRuntime().exec("cmd /c dir");
// process2.waitFor();



但是不能得到自己想要的结果。。。执行一条还行,但是执行多条就有问题,请高手指点!!!

如何用Java实现本地dos命令下的多条指令!!!想copy , dir 。。。等
谢谢!!!
...全文
评论 5
收藏 已收藏
分享
返回顶部
zings
Java 51,407 成员 86,132 内容