title: How to return spawned process exit code in Expect script?
body: <p>I use expect for running test scripts.
  Tests return success/failure through exit code. But expect return equivalent exit code.
  How to make expect return proper exit status?</p>
  
  <p>My tests are sql scripts run with <em>psql</em> (postgresql command processor).
  Since psql doesn't allow to specify database password as a command line parameter, <em>expect scripts</em> do that.</p>
  
  <p>So, my expect script looks like:</p>
  
  <pre><code>spawn $SPAWN_CMD
  expect {
          -re "Enter password for new role:" {
                  send "$PWPROMPT\n"
                  exp_continue
          } -re "Enter it again:" {
                  send "$PWPROMPT\n"
                  exp_continue
          } -re "Password(.*)" {
                  send "$PASSWORD\n"
                  exp_continue
          } -re "Password(.*):" {
                  send "$PASSWORD\n"
                  exp_continue
          } eof
  }
  </code></pre>