【问题标题】:Get output of "getprop | grep" shell command获取“getprop | grep” shell 命令的输出
【发布时间】:2013-11-21 07:18:37
【问题描述】:

我正在尝试获取命令“getprop | grep”的输出。

这是我的代码:

    public static void propFinder(String Prop) {
        try {
              Process process = Runtime.getRuntime().exec("getprop | grep "+Prop);
              BufferedReader bufferedReader = new BufferedReader(
              new InputStreamReader(process.getInputStream()));

              StringBuilder log=new StringBuilder();
              String line;
              while ((line = bufferedReader.readLine()) != null) {
                log.append(line + "\n");
              }
              Log.e(TAG,log.toString());
            } catch (IOException e) {
            }
    }

我想找出有关特定道具的信息。例如,“init.svc.sdcard”。

这是日志输出:

 11-21 09:16:04.143: I/Choreographer(14514): Skipped 40 frames!  The application may be doing too much work on its main thread.
 11-21 09:16:05.583: E/PropFinder(14514): grep

忘了说,如果我只发出 getprop,我会得到一个很好的输出,但它是不完整的。 谷歌搜索,使用了我发现的所有发出命令的方法。都是一样的。

我不知道它是否有帮助,但我有可用的 roottools 库。 (尝试使用他们的方法,结果相同)。

【问题讨论】:

    标签: java android shell output


    【解决方案1】:

    你为什么不为此使用 grep4j?

    public static void propFinder(String Prop) {
            GrepResults lineContainingTheProp = grep(constantExpression(Prop),  on(propertyFileProfile()));
            log.append(lineContainingTheProp);
    }
    

    【讨论】:

    • 不,它没有帮助,因为我不想从文件中读取。抱歉回复晚了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 2018-02-11
    • 2013-08-21
    • 2012-02-07
    • 1970-01-01
    相关资源
    最近更新 更多