ProcessBuilder builder = new ProcessBuilder(命令,参数,参数。。。);

Process process = builder.start();

br = new BufferedReader(new InputStreamReader(process.getInputStream()));

可以从br中读取日志信息

 

根据ID杀掉进程

String os = System.getProperty("os.name");
        try {
            if (os != null && os.startsWith("Windows")){
                for (int i = 0; i < pid.size(); i++) {
                    Runtime.getRuntime().exec("Taskkill /f /IM " + pid.get(i));
                }
            }else{
                for (int i = 0; i < pid.size(); i++) {
                    System.out.println("关闭linux进程");
                    String[] cmd ={"sh","-c","kill -9 "+pid.get(i)};
                    Runtime.getRuntime().exec(cmd);
                }
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

相关文章:

  • 2021-06-23
  • 2021-12-19
  • 2021-03-31
  • 2022-02-08
  • 2022-12-23
  • 2021-10-26
猜你喜欢
  • 2021-06-09
  • 2021-06-18
  • 2022-12-23
  • 2021-07-12
  • 2022-02-01
相关资源
相似解决方案