巨人肩:
ProcessBuilder.redirectErrorStream()方法
ProcessBuilder 用法示例
【Android问题记录|【Android】 ProcessBuild Process su 命令】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, envProcess 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();
...