简体   繁体   English

Android:在非根目录设备上运行脚本

[英]Android: run a script on non-rooted device

Can I run my binary executable file or script bash file on a non-rooted device? 我可以在非root用户的设备上运行二进制可执行文件或脚本bash文件吗? I have a small script like this: 我有一个像这样的小脚本:

#helloworld.sh
echo "hello world"

I saved it in /sdcard and try to run, but i got "Permission denied" . 我将其保存在/sdcard并尝试运行,但是出现“权限被拒绝”的提示 I have researched, the reason is Execute permissions on the SDCard is blocked. 我已经研究过,原因是SDCard执行权限被阻止。

Is it possible to run? 可以跑步吗? How can I do that without SU command? 没有SU命令怎么办? I think it is very helpful if somehow can execute any script file. 我认为如果可以执行任何脚本文件将非常有帮助。

在非root用户的设备上,可以使用sh命令在SDcard上运行脚本:

    adb shell sh path_to_script_on_sdcard/script.sh

Oh, I can run my script without SU permission, just use sh command: 哦,我可以在没有SU许可的情况下运行脚本,只需使用sh命令:

$ cd /sdcard
$ sh helloworld.sh
hello world

I think we cannot do the same with a binary executable file. 我认为我们无法对二进制可执行文件执行相同的操作。

For a shell script you can setup Termux or Terminal Emulator in your phone, enable Storage permission for it, launch it and than run the script like this: 对于外壳程序脚本,您可以在手机中设置TermuxTerminal Emulator为其启用存储权限,启动它,然后运行脚本,如下所示:

sh PATH_TO_FILE

Replace PATH with the path of file under /sdcard. 将PATH替换为/ sdcard下文件的路径。 It should work. 它应该工作。

To run a compatible binary, move the file from sdcard into Termux's home using: 要运行兼容的二进制文件,请使用以下命令将文件从sdcard移至Termux的主目录:

mv PATH_TO_FILE $HOME

Then verify and enable, using chmod +x $HOME/FILENAME if necessary, the executable permission on that moved file and run it. 然后根据需要使用chmod +x $HOME/FILENAME验证并启用该已移动文件的可执行权限并运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android : 使用非 root 的 android 设备捕获 HTTP 请求 - Android : Capturing HTTP Requests with non-rooted android device 非root用户设备上的Android用户空间文件系统驱动程序? - Android userspace filesystem driver on non-rooted device? 以编程方式在Android设备上创建Google帐户(非root用户设备) - Creating a google account on android programatically (non-rooted device) 是否可以在非 root 的 android 手机上运行本机 arm 二进制文件? - Is it possible to run a native arm binary on a non-rooted android phone? 如何重新启动非root用户的设备? - how to restart a non-rooted device? 在非root用户的Android上模拟主机文件 - Emulate hosts file on non-rooted Android 通过Google TV(Android非根设备)从端口查找pid - find pid from port over Google TV (Android non-rooted device) 是否真的有一种方法可以在不使用电缆的情况下将 ADB 命令发送到非 root 的 android 设备? - Is there truly a way to send ADB commands without the usage of a cable to a non-rooted android device? 亚行无线+ Windows +非根目录设备+挂起问题 - ADB Wireless + Windows + Non-rooted Device + Hang Issue 外部指纹扫描仪,用于无根Android平板电脑 - External fingerprint scanner for non-rooted Android tablets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM