以编程方式执行 shell 命令
我想通过程序执行这个shell命令。我该怎么做呢?
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们可以使用 Runtime 类来执行 shell 命令。
上面的代码将为给定命令 ls 创建一个本机进程,并将返回与 Process 对象相同的进程。
有关它的更多详细信息查看此处
We can execute shell comands by using Runtime class.
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
您应该将此处使用的确切语法写入
.bat
文件中,然后执行它。You Should write the exact syntax you used here in a
.bat
file, and then just execute it.看来您在 Microsoft 工作站上,因此考虑使用批处理会给您带来以下结果:
第一种方法:留在您的工作站上并发送有用的命令
唯一的事情是您将启动和关闭 3 个 shell,但事实并非如此并发出。
第二种方法:留在您的工作站上,在 sdcard 上发送一个 sh 脚本,并
使用包含以下内容的“myscript.sh”执行它:
请记住,在 Microsoft 工作站上创建的 Android shell 脚本具有 CRLF 行结尾!
在类 UNIX 系统上,您只需要使用 LF 来结束行!
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
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
with "myscript.sh" containing :
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 !