代码如下

                       BufferedReader reader = null;
                       String cmd = "netstat -anp|grep :8080";//命令中有管道符 | 需要如下执行命令
                        Process process = Runtime.getRuntime().exec(new String[]{"sh", "-c", cmd});
                        reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        String line = null;
                        while ((line = reader.readLine()) != null) {
System.out.println("*** " + line); }              

 

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-27
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
相关资源
相似解决方案