多个超级用户命令 Android
我正在尝试运行这个:
String[] hin1 = { "su", "-c",
"mount -o remount,rw -t yaffs2 /dev/block/mtdblk3 /system" };
try {
Runtime.getRuntime().exec(hin1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] hin2 = { "su", "-c", "m /system/etc/hosts" };
try {
Runtime.getRuntime().exec(hin2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] hin = { "su", "-c",
"cp /sdcard/hosts /system/etc/" };
try {
Runtime.getRuntime().exec(hin);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
遗憾的是,只有当我为每个操作创建一个新按钮时,它才起作用。:(
有没有一种方法可以同时运行多个命令?
谢谢
I'm tring to run this:
String[] hin1 = { "su", "-c",
"mount -o remount,rw -t yaffs2 /dev/block/mtdblk3 /system" };
try {
Runtime.getRuntime().exec(hin1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] hin2 = { "su", "-c", "m /system/etc/hosts" };
try {
Runtime.getRuntime().exec(hin2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] hin = { "su", "-c",
"cp /sdcard/hosts /system/etc/" };
try {
Runtime.getRuntime().exec(hin);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Sadly it is only working when I make for every action a new button.. :(
Is there a way to run more than one command at once??
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不这么认为它也有效,我尝试了以下代码:
命令 su -c chmod 777 dev/test1 的唯一按钮(用于更改 dev 目录中一个日志文件的权限),但它不起作用。
这有什么问题。有人可以指出缺少什么吗?
我什至将这一行放入 Androidmanifest.xml 以及
Rgds 中,
索拉布
Don't think so its working also , I tried the following code :
only button for command su -c chmod 777 dev/test1 (for changing the permission of one log file in dev directory) but it didn't work.
Whats wrong in this.Can some one point out whats missing.
I have even put this line in the Androidmanifest.xml as well
Rgds,
Saurabh
根据 su 命令的实现方式(即,如果它启动的东西类似于在更典型的 Linux 上那样的功能强大的 shell),您可以通过用分号分隔多个命令来将它们组合成一个字符串。
您还可以创建一个包含多个命令的 shell 脚本,并使用 su 来启动它,尽管您可能需要将其放在可执行位置。
Depending on how the su command is implemented (ie, if it's launching something approaching a capable shell as it would on a more typical linux), you may be able to combine multiple commands into one string by separating them with semicolons.
You could also make a shell script containing multiple commands and use su to launch that, though you may need to put it in an executable location.
您不会让一个命令在下一个命令开始之前完成。尝试在 exec 之后添加 waitFor:
You're not letting one command finish before the next one starts. Try adding a waitFor after the exec: