java中使用Process执行linux命令
代码如下
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); }