java执行命令行命令

 

 

package javai;

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class IOTest {

    public static void main(String[] args) {
        try {
            Process pro = Runtime.getRuntime().exec("ping www.baidu.com");
            String line;
            BufferedReader buf = new BufferedReader(new InputStreamReader(pro.getInputStream()));
            while ((line = buf.readLine()) != null)
                System.out.println(line);
        } catch (

        Exception e)

        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

 

 

 

 


正在 Ping www.a.shifen.com [220.181.111.188] 具有 32 字节的数据:
来自 220.181.111.188 的回复: 字节=32 时间=28ms TTL=54
来自 220.181.111.188 的回复: 字节=32 时间=28ms TTL=54
来自 220.181.111.188 的回复: 字节=32 时间=28ms TTL=54
来自 220.181.111.188 的回复: 字节=32 时间=28ms TTL=54

220.181.111.188 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 28ms,最长 = 28ms,平均 = 28ms

posted @ 2017-01-21 10:16  smallyaohailu  阅读(3124)  评论(0编辑  收藏  举报