码上敲享录 > linux系统常见问题 > java如何执行多行linux命令

java如何执行多行linux命令

上一章章节目录下一章 2018-08-01已有5941人阅读 评论(0)

java如何执行多行linux命令?

解决方法:

直接举例说明,使用Runtime.getRuntime().exec执行多行linux命令使用分号“;”隔开即可,亲试有效!

public static void main(String[] args) throws Exception {

String[] cmd = new String[] { "/bin/sh", "-c", "iptables -I INPUT -s 211.1.0.24 -j DROP;iptables -I INPUT -s 211.1.0.25 -j DROP" };

        try {

        Runtime.getRuntime().exec(cmd);

       } catch (Exception e) {

           e.printStackTrace();

       }

}


本文地址:http://www.yayihouse.com/yayishuwu/chapter/1386

向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交