巨人肩:
ProcessBuilder.redirectErrorStream()方法
How to run ProcessBuilder with list of commands?
Process requires redirected input
ProcessBuilder与Runtime.getRuntime().exec分别创建进程的区别
说我想说的:
想在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<String> list = new ArrayList();
list.add("su");
list.add(cmd);
pb = new ProcessBuilder(list);
p = pb.start();
...