0

I was experimenting with some shell commands on a rooted Nexus 7 tablet and I found that only the commands that seem like they wouldn't need root privilege are being executed.

For example, if I call:

  Process process = Runtime.getRuntime().exec("su -c mkdir /sdcard/test");

the directory is created. But if I call:

  Process process = Runtime.getRuntime().exec("su -c mkdir /system/test");

Nothing happens.

(I have tried all sorts of commands, and tried all sorts of different syntax in case something was off, but only commands that I wouldn't need root access for get executed)

When I try to execute this command, I get the popup from SuperUser and grant my application root privilege but is there something else that I am missing? I have looked all around and as far as I can tell this should work.

Thanks.

1 Answer 1

1
  1. You must quote the argument to mkdir, otherwise su will assume that /system/test is a user name and fail to run.

    Process process = Runtime.getRuntime().exec("su -c \"mkdir /path/to/test\"");

  2. Some areas of the filesystem, such as /system, are read only due to the way the filesystem is organized/mounted. Root access won't change that, your command will still fail.

To verify whether what you're trying to do is possible, install a terminal emulator on the device and run the command by hand first.

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

2 Comments

Ok thanks! What I am really trying to do is use the "mount" command to mount a connected USB OTG device. Is this going to be impossible due to the filesystem? When I plug in the device, a file is created at /dev/bus/usb/001. Is there any way to call mount and mount it to the filesystem?
You can possibly mount it with something like mount /dev/bus/usb/001 /mnt/foo, but mind the quoting when you pass the command to su.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.