我想在android上的一个进程中设置两个命令。
我知道nativeProcess = Runtime.getRuntime().exec("su");
但是我想在同一个过程中添加whoami。这可能吗?
答案 0 :(得分:0)
su -c "command"
将以超级用户身份运行您的命令(类似于基于Debian的系统中的sudo
)
答案 1 :(得分:0)
试试这个:
public static void go()
{
String[] command = {"/system/bin/sh", "-c", "ps | grep apps ; ls"};
ProcessBuilder processBuilder = new ProcessBuilder(command);
try {
Process process =processBuilder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:\n",
Arrays.toString(command));
while ((line = br.readLine()) != null) {
System.out.println(line);
Log.e("output of go-->", "==>"+line);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}