首页 > 系统相关 >android root 运行 shell

android root 运行 shell

时间:2022-08-29 13:45:03浏览次数:47  
标签:Exception outputStream su shell catch new android root

public class shell {
    static void shell(String sh) throws Exception {
        try{
            Process su = Runtime.getRuntime().exec("su");
            DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

            outputStream.writeBytes(sh+"\n");
            outputStream.flush();

            outputStream.writeBytes("exit\n");
            outputStream.flush();
            su.waitFor();
        }catch(IOException e){
            throw new Exception(e);
        }catch(InterruptedException e){
            throw new Exception(e);
        }
    }

    static void shell(String[] sh) throws Exception {
        try{
            Process su = Runtime.getRuntime().exec("su");
            DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

            for(String str : sh){
                outputStream.writeBytes(str+"\n");
            }
            outputStream.flush();

            outputStream.writeBytes("exit\n");
            outputStream.flush();
            su.waitFor();
        }catch(IOException e){
            throw new Exception(e);
        }catch(InterruptedException e){
            throw new Exception(e);
        }
    }
}
//调用:
try {
     shell.shell(new String[]{"echo hello","echo world"});
   shell.shell("echo 'hello world'");
} catch (Exception e) { e.printStackTrace(); }

 

标签:Exception,outputStream,su,shell,catch,new,android,root
From: https://www.cnblogs.com/laremehpe/p/16635669.html

相关文章

  • 【ubuntu 18.04 Server】配置root密码,并设置远程访问
    1、设置root密码使用具有root权限的账户执行sudopasswdroot   2、配置远程ssh访问sudoapt-getinstallopenssh-server编辑配置文件sudovim/etc/ss......
  • win10+Android(华为)系统原生日历同步方案+Sol日历桌面显示
    前言:本文是参考了其他博客基础上,新增了Android的免费桌面【月试图显示】功能、以及适配于上海交通大学的Canvas教学日历。方便进行多设备同步的日历管理、任务提醒。目录......
  • 实时语音驱动实现Android端Avatar虚拟人表情表达
    语音驱动虚拟人功能简介ZEGOAvatarSDK提供了语音驱动功能,通过声音的声波信息,实时驱动当前虚拟人物的嘴形变化,使得虚拟形象能够和真人一样进行自然的情绪表达。可广泛......
  • shell脚本LNMP
    #!/bin/bash#安装nginx服务#########安装nginx服务################systemctlstopfirewalldsystemctldisablefirewalldsetenforce0#安装依赖包yum-yinstal......
  • PowerShell教程 - 程序性能和BUG分析工具
    更新记录转载请注明出处。2022年8月29日发布。2022年8月29日从笔记迁移到博客。程序性能和BUG分析工具https://hibernatingrhinos.com/products/efprofhttps://s......
  • PowerShell教程 - 异步处理(Asynchronous Processing)
    更新记录转载请注明出处。2022年8月29日发布。2022年8月29日从笔记迁移到博客。异步处理(AsynchronousProcessing)休眠(Sleep)指定时间Start-Sleep实例:休眠1秒S......
  • PowerShell教程 - 模块管理(Modules Management)
    更新记录转载请注明出处。2022年8月29日发布。2022年8月29日从笔记迁移到博客。模块管理(ModulesManagement)模块和管理单元(ModulesandSnap-Ins)Moduleswerein......
  • linux-shell
    shellShell入门创建hellworld.sh文件多命令处理......
  • Linux Kernel in a Nutshell - 7
    CustomizingaKernel原文链接我的博客以·问题·做关键字搜索,还有问题构建你自己的Linux内核版本最困难的部分,应该就是确定哪一个驱动以及配置选项是你的设备需要的......
  • Linux Kernel in a Nutshell - 8
    KernelConfigurationRecipes原文链接我的博客前面介绍了重新配置内核的机制,本章介绍制作自己的内核通常会遇到的那些问题,并给出对应指令来处理它。DisksLinux内核......