Question

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.

Was it helpful?

Solution

  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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top