title: java bash command problem
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5886935/how-do-i-get-the-bash-command-exit-code-from-a-process-run-from-within-java">How do I get the bash command exit code from a Process run from within Java?</a>  </p>
  </blockquote>
  
  
  
  <p>Hi, I have a program which is a simple decrypts another file using bash command <code>./nv0914 &lt; nv0914.challenge</code> where nv0914 is a unix executable file and nv0914.challenge is a text file used for decryption. Now when i am running it from bash and just after that if I run the command <code>echo ${?}</code> I am getting a value 0, which is good. But now I have to implement an attack and for that I need to get the exit value printed through a java program. I have this code as if now:</p>
  
  <pre><code>import java.io.*;
     import java.util.*;
  
     public class ExecBashCommand {
       public static void main(String args[]) throws Exception {
  
  
         Runtime runtime = Runtime.getRuntime();
         Process process = runtime.exec("./nv0914 &lt; nv0914.challenge");
  
        /* InputStream is = process.getInputStream();
         InputStreamReader isr = new InputStreamReader(is);
         BufferedReader br = new BufferedReader(isr);
         String line;*/
  
  System.out.println("Exit Code: "+process.exitValue()); 
         //System.out.printf("Output of running %s is:", Arrays.toString(args));
  
        /* while ((line = br.readLine()) != null) {
           System.out.println(line);
         }*/
  
       }
      } 
  </code></pre>
  
  <p>But this program is giving me an error :</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalThreadStateException: process hasn't exited
          at java.lang.UNIXProcess.exitValue(UNIXProcess.java:172)
          at ExecBashCommand.main(ExecBashCommand.java:16)
  </code></pre>
  
  <p>Any suggestions as to how to get the exit value. Thanks </p>