用java执行shell命令

来源:互联网 发布:富士通扫描仪软件 编辑:程序博客网 时间:2024/04/30 17:46
    public static String getPhysicalAddress() {        Process p = null;         try {            // 执行ipconfig /all命令            p = new ProcessBuilder("ipconfig", "/all").start();        } catch (IOException e) {            return "";        }        byte[] b = new byte[1024];        int readbytes = -1;        StringBuffer sb = new StringBuffer();        // 读取进程输出值        InputStream in = p.getInputStream();        try {            while ((readbytes = in.read(b)) != -1) {                sb.append(new String(b, 0, readbytes));            }         } catch (IOException e1) {        } finally {            try {                in.close();            } catch (IOException e2) {            }        }         return sb.toString();    }

转自:java通过ProcessBuilder执行本地shell命令 获取ip配置信息 - java代码库 - 云代码 http://yuncode.net/code/c_50a5e9ef2258c96
原创粉丝点击