zoukankan      html  css  js  c++  java
  • Java——通过Java代码启动批处理文件

    作者专注于Java、架构、Linux、小程序、爬虫、自动化等技术。 工作期间含泪整理出一些资料,微信搜索【javaUp】,回复 【java】【黑客】【爬虫】【小程序】【面试】等关键字免费获取资料。技术交流、项目合作可私聊。 微信:shuhao-99999 

    前言

    通过Java代码启动批处理文件

    例如,通过代码启动Tomcat,只需要把tomcat的startup.bat传入到方法里面就可以了! 

    public void exeCmd(String batPath) {
        StringBuilder sb = new StringBuilder();
        try {
            Process child = Runtime.getRuntime().exec(batPath);
            InputStream in = child.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line + "\n");
            }
            in.close();
            try {
                child.waitFor();
                logger.info("call cmd process finished");
            } catch (InterruptedException e) {
                logger.error("faild to call cmd process cmd because " + e.getMessage());
            }
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }

  • 相关阅读:
    A. Ivan the Fool and the Probability Theory
    C2. Good Numbers (hard version)
    C. p-binary
    H. Happy Birthday
    idea使用goeasy实现webSocket
    idea新建一个maven项目
    FreeMaker入门介绍
    mui预加载
    mui底部选项卡切换实现
    BootStrap 学习笔记一
  • 原文地址:https://www.cnblogs.com/shuhao66666/p/15196332.html
Copyright © 2011-2022 走看看