public static void main(String[] args) throws IOException { Runtime run = Runtime.getRuntime(); Process pro = run.exec("ping 127.0.0.1 -t "); BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream())); String str = ""; while ((str = br.readLine()) != null) { System.out.println(str); // 这里你增加一个计数器,判断行数 } br.close(); pro.destroy(); }
public static void main(String[] args) throws IOException { Runtime run = Runtime.getRuntime(); Process pro = run.exec("ping 127.0.0.1 -t "); BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream())); String str = ""; while ((str = br.readLine()) != null) { System.out.println(str); // 这里你增加一个计数器,判断行数 } br.close(); pro.destroy(); }
使用Java的Runtime 就可以了,代码如下: /* * Created on Jan 3, 2008 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package org.mytech.test;import java.io.*;/** * @author 806883 * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */public class RunPing { public static void main(String[] argv) { try { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("ping www.163.com"); BufferedReader reader = new BufferedReader(new InputStreamReader( process.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (Exception e) { e.printStackTrace(); } } }
Runtime run = Runtime.getRuntime();
Process pro = run.exec("ping 127.0.0.1 -t ");
BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String str = "";
while ((str = br.readLine()) != null) {
System.out.println(str); // 这里你增加一个计数器,判断行数
}
br.close();
pro.destroy();
}
Runtime run = Runtime.getRuntime();
Process pro = run.exec("ping 127.0.0.1 -t ");
BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String str = "";
while ((str = br.readLine()) != null) {
System.out.println(str); // 这里你增加一个计数器,判断行数
}
br.close();
pro.destroy();
}
/*
* Created on Jan 3, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.mytech.test;import java.io.*;/**
* @author 806883
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/public class RunPing { public static void main(String[] argv) {
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("ping www.163.com");
BufferedReader reader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}