title: Using Ruby to call a shell script exit code always returns as 0
body: <p>I am using Ruby to call a shell script via:</p>
  
  <pre><code>%x[ /root/script.sh -k -m -l -w -p]
  exitCode = %x[echo $?]
  
  if exitCode != 0
    do something
  else
    do something else
  end
  </code></pre>
  
  <p>My problem is the exit code is always equal to 0 even when I force the script to fail. How do I properly get the exit code of the script?</p>
  
  <p>EDIT:
  Ok came in this morning and started digging through the script as I could not get an error code of anything besides 0. The script looks something like this...</p>
  
  <pre><code>failed() {
        if [ "$1" -ne 0 ] ; then
            echo "$2 failed. INSTALLATION FAILED! Exiting.";
        exit 1;
      fi
  }
  
  {
  
  function 1
  function 2..
  function ..20
  
  } | tee -a logFile.log 
  </code></pre>
  
  <p>So the last thing that the script runs is always this log file meaning I never get the real exit code.</p>