美文网首页
java 执行cmd命令

java 执行cmd命令

作者: 好大一只鹏 | 来源:发表于2021-08-17 14:24 被阅读0次

报错结果:

找不到系统路径

处理:
在命令前加上cmd 即可。
例如:
String cmd1 = "cmd cd D:\\project\\autotest-console";
 Runtime run = Runtime.getRuntime();
try {
           Process process1 =  run.exec(ping);
           System.out.println(process1.waitFor());
           run.exec(cmd1);
           run.exec(command);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
. waitFor() 会返回是否执行成功   0 成功 1 失败
.

参考地址: https://zhuanlan.zhihu.com/p/33547017
https://zhuanlan.zhihu.com/p/44957705

相关文章

网友评论

      本文标题:java 执行cmd命令

      本文链接:https://www.haomeiwen.com/subject/fcgbbltx.html