android sudo and shell
来源:互联网 发布:js水仙花数 编辑:程序博客网 时间:2024/06/14 18:44
最近频繁用到su和shell的东西,在android上跑一些东西,贴下代码,做个笔记吧
SuperUserShell
public class SuperUserShell { private Process su; private DataOutputStream outputStream; void open() throws IOException { this.su = Runtime.getRuntime().exec("su"); this.outputStream = new DataOutputStream(su.getOutputStream()); } void write(String cmd) throws IOException, InterruptedException { outputStream.writeBytes(cmd + "\n"); outputStream.flush(); } void close() { if (su == null || outputStream == null) return; try { outputStream.writeBytes("exit\n"); outputStream.flush(); su.waitFor(); outputStream.close(); su.getInputStream().close(); su.getErrorStream().close(); } catch (Exception e) { e.printStackTrace(); } }}
Shell
public class Shell { private Process shell; private DataOutputStream outputStream; private BufferedReader responseStream; public void open() throws IOException, InterruptedException { this.shell = Runtime.getRuntime().exec("sh"); this.outputStream = new DataOutputStream(shell.getOutputStream()); this.responseStream = new BufferedReader(new InputStreamReader(shell.getInputStream())); } public void write(String cmd) throws IOException, InterruptedException { outputStream.writeBytes(cmd + "\n"); outputStream.flush(); } public String read() throws IOException, InterruptedException { String line; while (true) { if ((line = responseStream.readLine()) != null) break; } return line.trim(); } public void close() { if (shell == null || outputStream == null) return; try { outputStream.writeBytes("exit\n"); outputStream.flush(); shell.waitFor(); outputStream.close(); responseStream.close(); shell.getErrorStream().close(); } catch (Exception e) { e.printStackTrace(); } }}
阅读全文
0 0
- android sudo and shell
- shell 之su/sudo
- UBUNTU AND SUDO
- Shell中执行sudo命令
- python 使用 linux shell sudo
- sudo and samba file example
- 在shell脚本里执行sudo 命令
- crontab运行shell脚本报sudo错误
- shell脚本中sudo 自动输入密码
- shell中sudo和su命令
- sudo在shell脚本执行的问题
- shell中sudo和su命令
- 在shell脚本中使用sudo
- Shell Sudo With Password On Command
- php利用sudo权限执行shell脚本
- shell中sudo和su命令
- Defaults visiblepw php exec sudo shell 脚本
- Shell脚本——su、sudo
- 宏定义
- 计算机核心期刊排名及投稿信息
- spring项目无法引入@Resource注解的问题处理
- 相机工作原理
- Linux 入侵检测
- android sudo and shell
- 无头单链表排序
- bzoj3701,大力莫比乌斯反演
- 如何学习Linux
- 快速排序算法的实验
- Linux-awk命令
- Android对话框Dialog和DialogFragment
- UTF8 编码原理简介
- twisted之defer延迟