title: Exit value from bash script different when called from Java
body: <p>I'm executing some scripts from a Java class. There, I execute the scripts and wait for the results. However, when I execute these files, I don't get the real value of exit status from my scripts.</p>
  
  <p>If I execute the scripts like:</p>
  
  <pre><code>./relativePath/script.sh
  </code></pre>
  
  <p>And then I print the value:</p>
  
  <pre><code>echo $?
  </code></pre>
  
  <p>I <strong>get the correct value</strong>. But since I'm receiving it inside the Java program, I can't just print <code>$?</code>, but just receive the exit value using the class <code>Process</code> (all correct until here). So I do:</p>
  
  <pre><code>Process program;
  program = Runtime.getRuntime().exec(new String[]
                      {file});
          program.waitFor();
          if ( program.exitValue() == 0)
          {
              result = true;
          }
  </code></pre>
  
  <p>But as I said at the title of the question, when I execute the script in this way, I'm not getting the correct exit status value I'm waiting for.</p>
  
  <p><strong>Why</strong>?</p>
  
  <p>I've tried it with a C compiled program and It works fine, and checked that the output of the exec status in this case is also saved in <code>$?</code>. </p>
  
  <p>Thank you in advance!</p>