在Android的JNI方法执行以超级用户权限的命令 [英] Execute a command with superuser permission in JNI method in Android
本文介绍了在Android的JNI方法执行以超级用户权限的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java中,我能有这样的事情:
In Java, I can have something like this:
Process p = Runtime.getRuntime().exec("su");
DataOutputStream pOut = new DataOutputStream(p.getOutputStream());
pOut.writeBytes("find / -perm -2000 -o -perm -4000\n");
pOut.writeBytes("ps\n");
pOut.writeBytes("ls\n");
pOut.writeBytes("exit\n");
pOut.flush();
p.waitFor();
我知道,在执行JNI方法find命令,我们可以使用系统或的popen 功能。但我不知道如何与苏特权执行它?
I know that to execute the find command in JNI method, we can use system or popen function. But I don't know how to execute it with su privilege?
PS:由于系统功能叉一个新的子进程。我想有一个子进程产卵起来的Java执行类似多个命令。
PS: Since the system function forks a new child process. I want to have a single child process spawning up to execute multiple commands like in Java.
推荐答案
费米的答案是接近的,我已经测试过,对我来说了以下工作:
Femi answer is close, I have tested, the following works for me:
system("su -c \"find / -perm -2000 -o -perm -4000; ps; ls\"");
这篇关于在Android的JNI方法执行以超级用户权限的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文