Why does my "if (p.exitValue() != 0)" code run twice?
<p>When I execute a shell script using the method below, my "if (p.exitValue() != 0)" code runs TWICE when it is successful... anyone know why? Also, when the shell script fails, the else code runs once, and then the success code runs again anyway. What am I doing wrong? </p>

<pre><code>void exec(String commander){


            Process p = null;
        try {
            p = Runtime.getRuntime().exec(commander);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

           StreamGobbler errorGobbler = new 
           StreamGobbler(p.getErrorStream(), "ERROR"); 

           // any output? 
           StreamGobbler outputGobbler = new 
           StreamGobbler(p.getInputStream(), "OUTPUT"); 

           // kick them off 
           errorGobbler.start(); 
           outputGobbler.start(); 

           // any error??? 
           int exitVal = 1;
        try {
            exitVal = p.waitFor();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

        System.out.println("ExitValue: " + exitVal); 

        if (p.exitValue() != 0)
         {

        //SUCCESS Code RUNS TWICE

         }
         else {


            //FAILURE Code Runs Once, then Success Code Runs anyway!! WHY? 


         }

       }
</code></pre>
