【Android】 ProcessBuild Process su 命令

巨人肩:
ProcessBuilder.redirectErrorStream()方法

ProcessBuilder 用法示例

How to run ProcessBuilder with list of commands?

Process requires redirected input

ProcessBuilder与Runtime.getRuntime().exec分别创建进程的区别

ProcessBuilder API(Android)

说我想说的:
想在Android上使用su权限执行命令,可以尝试如下方法:

ProcessBuilder pb = new ProcessBuilder("su");
//othre pb setting,such as dir, env

Process p = pb.start();

OutputStream out;
out = p.getOutputStream();
out.write(cmd.getBytes());
...

曾经失败的尝试:

//失败1
pb = new ProcessBuilder("su",cmd);
p = pb.start();
...

//失败2
List list = new ArrayList();
list.add("su");
list.add(cmd);
pb = new ProcessBuilder(list);
p = pb.start();
...

你可能感兴趣的:(Android问题记录,android)