简体   繁体   English

使用批处理(.bat)文件自动执行adb shell命令

[英]Automating adb shell commands using batch(.bat) files

I regularly grant read/write/execute (chmod 777) permissions to different system files in Android phones(rooted phones). 我经常向Android手机(root手机)中的不同系统文件授予读/写/执行(chmod 777)权限。 Sometimes I add the chmod 777 command to the startup script, Just to save time. 有时我将chmod 777命令添加到启动脚本中,只是为了节省时间。 On Samsung Galaxy S6 phone I am updating the file(script): '/etc/init.sec.boot.sh', adding following command at the end of the file. 在三星Galaxy S6手机上我正在更新文件(脚本):'/ etc / init.sec.boot.sh',在文件末尾添加以下命令。

chmod 777 <filename>

This works fine from inside the adb shell using the following command 使用以下命令从adb shell内部工作正常

su
echo 'chmod 777 <filename>' >> /etc/init.sec.boot.sh

Now if I try to the same using a .bat file it gives me permission error. 现在,如果我尝试使用.bat文件,它会给我许可错误。 I am using the following command 我使用以下命令

adb shell su -c "echo \"chmod 777 <filename>\" >> /etc/init.sec.boot.sh"

Since this command was not working I copied the file to sdcard, modified it and then replaced the original file with the modified version. 由于此命令不起作用,我将文件复制到sdcard,修改它,然后用修改后的版本替换原始文件。 If I now read the contents of the file it reads exactly what I wanted, but the chmod command is never executed. 如果我现在读取文件的内容,它会准确读取我想要的内容,但chmod命令永远不会执行。 I restarted the phone several times but the file permission were not effected at all. 我重启了几次电话,但文件许可完全没有实现。 At this point if I run same command from inside the shell if works. 此时,如果我从shell内部运行相同的命令,如果工作。

su
echo 'chmod 777 <filename>' >> /etc/init.sec.boot.sh

At this point the last two lines in the init.sec.boot.sh files read like this. 此时,init.sec.boot.sh文件中的最后两行如下所示。

chmod 777 <filename>
chmod 777 <filename>

The last two lines seems exactly the same. 最后两行看起来完全一样。 The chmod command only works when it is written from inside the shell. chmod命令仅在从shell内部写入时才有效。 The only reasonable explanation I could think of is that there may be a different text encoding used by the windows command prompt and Android linux shell. 我能想到的唯一合理的解释是,windows命令提示符和Android linux shell可能使用不同的文本编码。 How to successfully execute the chmod command from .bat files (or even directly from command prompt). 如何从.bat文件(甚至直接从命令提示符)成功执行chmod命令。

PS: I did remounted /system to read/write. PS:我做了重装/系统读/写。

I guess the problem was the difference between the Windows EOL and Unix EOL. 我想问题是Windows EOL和Unix EOL之间的区别。

So I created a script inside the Linux System (Androids Linux System), to do the chmod stuff. 所以我在Linux系统(Androids Linux系统)中创建了一个脚本来做chmod的东西。 Used adb pull command to copy the .sh file to my Windows machine. 使用adb pull命令将.sh文件复制到我的Windows计算机。

Now my original batch file copies this script back to the phone and executes it. 现在我的原始批处理文件将此脚本复制回手机并执行它。 (I had to copy the script to /data/local inside the phone). (我不得不将脚本复制到手机内的/ data / local)。 This is working perfectly. 这很完美。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM