Android shell commands fail to find /data director

2019-08-13 23:48发布

问题:

In my application I'm doing:

try {
    String[] cmd = {"su", "-c",  "\"ls /data/\""}; //to debug, will be cp /src /dest

    ProcessBuilder builder = new ProcessBuilder(cmd);
    builder.redirectErrorStream(true);
    Process process = builder.start();
    InputStream is = process.getInputStream();

    Log.e("copy", is.toString());
    Log.e("copy", convertStreamToString(is));

    try {
        process.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
} catch (IOException e1) {
    e1.printStackTrace();
}

The app is installed in /system/app/ and running with root permissions.

I see SuperSu's overlay that it's granted permissions for the operation.

With the cp /src /dest in place of ls command above, it doesn't copy, so debugging with ls, I get:

tmp-mksh: ls /data: not found

Why is this, and how can I fix it?

NB: This is the same issue as this question, except that was resolved by adding external write permissions - I should note that both paths in my command are in /data/...

标签: android shell