首页 > 解决方案 > 使用 RootTools 获取 shell 命令的输出

问题描述

我想获取 shell 命令的输出,例如使用RootTools “ls -l”并将其传递给变量或数组,以便我可以操作它。

这是我使用但不起作用的代码。

final StringBuilder s = new StringBuilder();
final Command command = new Command(0, "ls -l") {      
    public void commandOutput(int id, String line) {
                    s.append(line);
                    super.commandOutput(id, line);
                    System.out.println(s.toString());
        }                   
    };

    try {
         RootTools.getShell(true).add(command);
    } catch (IOException | RootDeniedException | TimeoutException e) {
         e.printStackTrace();
    }

标签: androidroottools

解决方案


推荐阅读