title: How to capture the exit status of a shell command in Java?
body: <p>I'm creating a Junit test file for my CSVreader. I'm reading the contents of CSV files and writing the contents into another file. I want to compare them using diff utility and I want to use the exit status of diff to know whether the contents are same or not. Generally $? gives the exit status but I don't know how to capture it and use it in my code. Can anyone help me in this regard?</p>
  
  <p>This is how my code looks</p>
  
  <pre><code> boolean hasSameContents = false;
  
      command="diff "+mp.get("directory")+"/"+fileName+" "+mp.get("outdir")+"/"+fileName;
      p= Runtime.getRuntime().exec(command);
      p.waitFor();
  </code></pre>
  
  <p>After this I want to get the exit status and use it in a if condition like this </p>
  
  <pre><code> if(exit_status==0)
       hasSameContents = true;
    else
       hasSameContents = false;
  </code></pre>
  
  <p>Even alternative suggestions appreciated. :)</p>