More than one Superuser command Android

半世苍凉 提交于 2019-12-23 17:39:36

问题


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


回答1:


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




回答2:


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.




回答3:


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

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


来源:https://stackoverflow.com/questions/4846241/more-than-one-superuser-command-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!