我在Java里执行cmd命令: Process p = Runtime.getRuntime().exec("ping -w " + timeout + " " + "www.usc.edu");
目的是Ping一下与"www.usc.edu"的连接情况
我在cmd里面测试是,问题是如何获得其中的信息,比如 Lost Average ???
求助!我Linux和C都不好,请教!
public static void main(String[] args) throws IOException, InterruptedException {
// 执行ping命令
String cmdPing = "ping 127.0.0.1";
Runtime run = Runtime.getRuntime();
Process process = run.exec(cmdPing);
process.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("GBK")));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}