public static String runNetstat() { try { ProcessBuilder p = new ProcessBuilder("netstat.exe", "-noa", "-p", "tcp"); Process netstat = p.start();
java.io.BufferedReader input = new java.io.BufferedReader(new java.io.InputStreamReader(netstat.getInputStream(), "GBK"));
StringBuilder result = new StringBuilder(); String line = null; while ((line = input.readLine()) != null) { result.append(line).append("\n"); }
input.close(); netstat.destroy(); return result.toString(); } catch (Exception e) { return e.getMessage(); } }
不能waitfor,否则会一直等~~
|