在java中可以用public static boolean RootCommand(String command) {
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.d("*** DEBUG ***", "ROOT REE" + e.getMessage());
return false;
} finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// nothing
}
} Log.d("*** DEBUG ***", "Root SUC ");
return true; }就可以以root权限来运行了。
但是c++中应该是什么写呢?c++中的system函数可以执行命令,但是不知道这么写是root权限运行。