Adb Shell 分配伪终端解决方案
🔧 问题描述
在通过 adb shell
执行 shell 脚本时,遇到了权限拒绝的问题。即使分配了 root 权限,在 shell 外部执行脚本仍然会失败。
💡 解决方案
方法一:使用 -t 参数
通过搜索发现需要为 adb shell 分配伪终端,使用 -t
参数:
1 | adb shell -t "/sdcard/<your_shell>.sh" |
方法二:在构建脚本中使用
1 | exec { |
1 | ProcessBuilder("powershell", "-c","\"adb shell -t \"sh /sdcard/1.sh\"\"") |
⚠️ 常见错误
错误信息
1 | Remote PTY will not be allocated because stdin is not a terminal. |
✅ 最终解决方案
使用 -tt
参数
在 -t
后面再加一个 t
,即使用 -tt
参数来强制分配伪终端。
1 | adb shell -tt "/sdcard/<your_shell>.sh" |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 crowforkotlin!
评论