java执行客户端命令(windows与linux通用)

来源:互联网 发布:万德数据库怎么购买 编辑:程序博客网 时间:2024/05/21 18:50
import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;/** * 类说明 *  * @author nmj * @email bjahqj@163.com * @date 2017年5月17日 新建 */public class test {    public static void main(String[] args) {        // start        try {            Process pro = Runtime.getRuntime().exec("ping -w 4 www.baidu.com ");            InputStream is1 = pro.getInputStream();            BufferedReader buf = new BufferedReader(new InputStreamReader(is1));            String line = null;            while ((line = buf.readLine()) != null) {                if (line.indexOf("请求超时。") > -1) {                    System.out.println("error");                    break;                }            }        } catch (Exception e) {            // TODO: handle exception        }        // end    }}