Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getRuntime().exec和Processbuilder仅返回2行数据_Android - Fatal编程技术网

Android getRuntime().exec和Processbuilder仅返回2行数据

Android getRuntime().exec和Processbuilder仅返回2行数据,android,Android,我试图获得一个top命令输出并在UI中显示它。但是当我运行下面的代码(Runtime.exec和processbuilder)时,它只给出两行结果 有人能帮我吗? ` 及 `到目前为止没有答案。在摘要部分的正上方有一段代码,您可以使用它。它将您的输出重定向到Android中的一个文件:您希望看到的是什么?我正在运行下面的命令top-scpu-n1-m5,希望得到这样的输出。用户2%,系统10%,低0%,IRQ 0%用户2+Nice 0+Sys 8+Idle 67+IOW 0+IRQ 0+SIRQ

我试图获得一个top命令输出并在UI中显示它。但是当我运行下面的代码(Runtime.exec和processbuilder)时,它只给出两行结果

有人能帮我吗? `


`

到目前为止没有答案。在摘要部分的正上方有一段代码,您可以使用它。它将您的输出重定向到Android中的一个文件:您希望看到的是什么?我正在运行下面的命令top-scpu-n1-m5,希望得到这样的输出。用户2%,系统10%,低0%,IRQ 0%用户2+Nice 0+Sys 8+Idle 67+IOW 0+IRQ 0+SIRQ 0=77 PID用户PRNI CPU%S#THR VSS RSS PCY名称10954外壳20 0 14%R 1 5204K 1664K fg顶部10根20 0 1%S 1 0K 0K fg RCOOP/0 3根20 0 0%S 1 0K fg ksoftirqd/0 5根0-20 0%s10k0k fg kworker/0:0h7根20%s10k0k fg rcu预占
     String command = "ps";
    ProcessBuilder pb = new ProcessBuilder(command);
    try {
        Process process = pb.start();
        process.waitFor();
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
                            topcommandoutput.append(line+"\n");
        }

        reader.close();

    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    String command =  "top -s cpu -n 1 -m " + noofprocess;
   Process p;
   try {
       String line = "";
       p = Runtime.getRuntime().exec( command);
       p.waitFor();

       Scanner reader = new Scanner(new InputStreamReader(p.getInputStream()));

       while ((line = reader.nextLine())!= "null") {
           topcommandoutput.append(line+"\n");
       }
       ParseText(timestamp);
   } catch (Exception e) {
        e.printStackTrace();
   }