多个超级用户命令 Android

发布于 2024-10-15 04:22:51 字数 1030 浏览 7 评论 0原文

我正在尝试运行这个:

            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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

权谋诡计 2024-10-22 04:22:51

不这么认为它也有效,我尝试了以下代码:

public class GainrootActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


    }

    public void gainroot(View view)
    {
        String[] hin1 = { "su", "-c","chmod 777 dev/test1" };
        try {
                Runtime.getRuntime().exec(hin1);
            } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

  }
}

命令 su -c chmod 777 dev/test1 的唯一按钮(用于更改 dev 目录中一个日志文件的权限),但它不起作用。
这有什么问题。有人可以指出缺少什么吗?
我什至将这一行放入 Androidmanifest.xml 以及

<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />

Rgds 中,
索拉布

Don't think so its working also , I tried the following code :

public class GainrootActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


    }

    public void gainroot(View view)
    {
        String[] hin1 = { "su", "-c","chmod 777 dev/test1" };
        try {
                Runtime.getRuntime().exec(hin1);
            } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

  }
}

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

<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />

Rgds,
Saurabh

冬天的雪花 2024-10-22 04:22:51

根据 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.

时光清浅 2024-10-22 04:22:51

您不会让一个命令在下一个命令开始之前完成。尝试在 exec 之后添加 waitFor:

Runtime.getRuntime().exec(hin1).waitFor();

You're not letting one command finish before the next one starts. Try adding a waitFor after the exec:

Runtime.getRuntime().exec(hin1).waitFor();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文