1

My main aim is to run a something like below from within an Android application:

$(normal mode)su
#(root mode) chmod 777 <some file>

But the problem here is as soon the shell changes from $ --> # the chmod command doesn't work.

Another way of achieving this is to make a shell script, place it in the Android /data directory, and run it manually. But how can I run it from within the Android application, making sure that when the shell changes ($--> #) the functionality remains intact?

One more way is to run my script using the script manager application.

0

1 Answer 1

0

Try this

Process suProcess = Runtime.getRuntime().exec("su");

    DataOutputStream os = 
        new DataOutputStream(suProcess.getOutputStream());

   **strong text**
    for (String Command : /*your commands*/)
    {
      os.writeBytes(Command + "\n");
      os.flush();
    }

    os.writeBytes("exit\n");
    os.flush();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.