Automating adb shell commands using batch(.bat) files
<p>I regularly grant read/write/execute (chmod 777) permissions to different system files in Android phones(rooted phones). Sometimes I add the chmod 777 command to the startup script, Just to save time.
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.</p>

<p><code>chmod 777 &lt;filename&gt;</code></p>

<p>This works fine from inside the adb shell using the following command</p>

<pre><code>su
echo 'chmod 777 &lt;filename&gt;' &gt;&gt; /etc/init.sec.boot.sh
</code></pre>

<p>Now if I try to the same using a .bat file it gives me permission error. I am using the following command</p>

<pre><code>adb shell su -c "echo \"chmod 777 &lt;filename&gt;\" &gt;&gt; /etc/init.sec.boot.sh"
</code></pre>

<p>Since this command was not working I copied the file to sdcard, modified it and then replaced the original file with the modified version. If I now read the contents of the file it reads exactly what I wanted, but the chmod command is never executed. 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.</p>

<pre><code>su
echo 'chmod 777 &lt;filename&gt;' &gt;&gt; /etc/init.sec.boot.sh
</code></pre>

<p>At this point the last two lines in the init.sec.boot.sh files read like this.</p>

<pre><code>chmod 777 &lt;filename&gt;
chmod 777 &lt;filename&gt;
</code></pre>

<p>The last two lines seems exactly the same. The chmod command only works when it is written from inside the 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.
How to successfully execute the chmod command from .bat files (or even directly from command prompt).</p>

<p>PS: I did remounted /system to read/write.</p>