码迷,mamicode.com
首页 > 编程语言 > 详细

[Java] Runtime Exec

时间:2014-08-31 01:36:40      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   java   for   div   代码   

经常用到Runtime的exec方法,记录一下标准用法,便于以后复制代码。

        Process process;
        String cmd = "cat /sys/devices/virtual/mxc_edid_class/mxc_edid_dev/timing";
        StringBuffer sb = new StringBuffer("");
        try {
            process = Runtime.getRuntime().exec("su");
            String line = null;
            DataOutputStream dos = new DataOutputStream(
                    process.getOutputStream());
            dos.writeBytes(cmd + "\n");
            dos.flush();
            dos.writeBytes("exit\n");
            dos.flush();
            BufferedReader bf = new BufferedReader(new InputStreamReader(
                    process.getErrorStream()));
            while ((line = bf.readLine()) != null) {
            }
            BufferedReader bf2 = new BufferedReader(new InputStreamReader(
                    process.getInputStream()));
            while ((line = bf2.readLine()) != null) {
                sb.append(line);
            }
            process.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

 

[Java] Runtime Exec

标签:style   blog   color   os   io   java   for   div   代码   

原文地址:http://www.cnblogs.com/all-for-fiona/p/3944473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!