相关疑难解决方法(0)

通过ADB以root身份启动脚本

我已经创建了一个脚本来安装分区并在我的Android系统中执行一些操作.我将脚本保存为Android的/ bin文件夹中的install.sh.

我想从ADB调用脚本,它本身是从Windows上的批处理文件调用的,但它需要以root身份执行.

我尝试的第一个解决方案是使用调用脚本

adb shell "su -c sh /bin/script.sh"
Run Code Online (Sandbox Code Playgroud)

但它不起作用,因为它给我一个shell访问权限(具有root权限),但没有执行任何操作.我也试着打电话

adb root "sh /bin/script.sh"
Run Code Online (Sandbox Code Playgroud)

但我得到以下错误

adbd cannot run as root in production builds
Run Code Online (Sandbox Code Playgroud)

然后我试着写

su -c "command"
Run Code Online (Sandbox Code Playgroud)

对于我的脚本中需要root访问权限的所有命令,但我遇到了同样的问题.当我运行脚本时,我只获得了一个root shell,并且没有执行任何操作.

如果我手动使用第一个解决方案(例如我调用adb shell su,然后是我的脚本),它就可以了.但是,重点是自动化该过程,以便可以从另一个脚本调用adb shell.

你知道我怎么能做到这一点吗?

谢谢 !

shell android root adb

25
推荐指数
1
解决办法
8万
查看次数

Android:写入失败:EPIPE(Broken pipe)写入文件出错

我试图以编程方式截取Android屏幕截图.我做了以下代码:

private void getsnap(){
    try{
        Process sh = Runtime.getRuntime().exec("su", null, null);
        OutputStream os = sh.getOutputStream();
        String filePath = this.getFilesDir().getPath().toString() + "/fileName1.jpeg";
        os.write(("/system/bin/screencap -p " + filePath).getBytes("ASCII"));
        os.flush();
        os.close();
        sh.waitFor();       
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

java.io.IOException: write failed: EPIPE (Broken pipe)

请有人帮忙吗?我已经检查过其他帖子,但我找不到解决问题的方法.


编辑:

请注意,错误发生在行中os.write().

android outputstream file epipe android-permissions

18
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×2

adb ×1

android-permissions ×1

epipe ×1

file ×1

outputstream ×1

root ×1

shell ×1