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?