0

I want to fire "top" command on terminal from java prgram and store the output of it in some variable. i am using ubuntu 12.04. I used following code to run the command:

    Process proc = null;
    try {
        String cmd[] = {"gnome-terminal", "-x", "bash", "-c", "top; echo '<enter>';" };


        proc = Runtime.getRuntime().exec(cmd, null);
    } catch (IOException e) {
        e.printStackTrace();
    }

now I want to capture top command's output in some variable. how should i do it? can anyone help?

Neha
  • 23
  • 4
  • Consider using a ProcessBuilder. Grab a reference of Process's InputStream and process it like you would any InputStream, check out SO, there are plenty of examples... – MadProgrammer Nov 28 '14 at 19:52
  • http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program – Tobi Nov 28 '14 at 19:55

0 Answers0