首页 > 代码库 > [Java] Runtime Exec
[Java] Runtime Exec
经常用到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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。