2

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

3 Answers 3

7

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

Sign up to request clarification or add additional context in comments.

Comments

2

You Should write the exact syntax you used here in a .bat file, and then just execute it.

1 Comment

this works if you have access to the system you're running the program on, but if your prog will be run on an unknown system it most likely will not have that batch file. you could create it programmatically and then execute it, but that probably isn't the best way to do this.
1

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 !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.