I want to execute this shell commands by program. How can I do it?
cd C:\android-sdk\platform-tools adb shell su mount -t rfs -o remount,rw /dev/block/stl9 /system cp /sdcard/MyApp.apk /system/app/MyApp.apk
We can execute shell comands by using Runtime class.
Runtime.getRuntime().exec("ls");
The above piece of code will create a native process for given command ls, will return same process as a Process object.
For more details about it Check here
You Should write the exact syntax you used here in a .bat
file, and then just execute it.
It seems you are on a Microsoft station so considering using batch would give you this :
1st method : Stay on your station and send usefull commands
cd C:\android-sdk\platform-tools adb shell "su -c 'mount -o rw,remount /system'" adb shell "su -c 'cp /sdcard/MyApp.apk /system/app/MyApp.apk'" adb shell "su -c 'mount -o ro,remount /system'"
The only thing is you will launch and close 3 shells but its not really and issue.
2nd method : Stay on your station send a sh script on sdcard and execute it
cd C:\android-sdk\platform-tools adb push myscript.sh /sdcard/ adb shell "su -c 'sh /sdcard/myscript.sh'"
with "myscript.sh" containing :
#!/system/bin/sh mount -o rw,remount /system cp /sdcard/MyApp.apk /system/app/MyApp.apk mount -o ro,remount /system
Remember that Android shell scripts created on Microsoft station have CRLF line ending ! You need to get LF only ending your lines on UNIX like systems !