title: Collect Linux command output
body: <p>I am now on a linux machine. I have a Java program which would run some linux command, for example <code>ps</code>, <code>top</code>, <code>list</code> or <code>free -m</code>. </p>
  
  <p>The way to run a command in Java is as follows:</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec("free -m");
  </code></pre>
  
  <p>How could I collect the output by Java program? I need to process the data in the output.</p>