3

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

Paul
  • 321
  • 1
  • 5
  • 8
  • try taking a look at the following question: http://stackoverflow.com/questions/4905743/android-how-to-gain-root-access-in-an-android-application – Muzikant Dec 09 '11 at 14:07

3 Answers3

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

saurabh
  • 11
  • 1
0

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.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • 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. Worked :-* – Paul Jan 30 '11 at 23:50
0

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

Runtime.getRuntime().exec(hin1).waitFor();
Kevin TeslaCoil
  • 10,037
  • 1
  • 39
  • 33