title: How to get the exit code of spawned process in expect shell script?
body: <p>I am trying to execute a script that executes an EXPECT script and a spawned process which has exit code in it. But I'm unable to get the exit code of the spawned process to main script. I'm always getting zero as success.</p>
  
  <p>expect script is :</p>
  
  <pre><code> [Linux Dev:anr ]$ cat testexit.sh
   #!/bin/bash
   export tmp_script_file="/home/anr/tmp_script_temp.sh"
   cp /home/anr/tmp_script $tmp_script_file
   chmod a+x $tmp_script_file
   cat $tmp_script_file
   expect &lt;&lt; 'EOF'
   set timeout -1
   spawn  $env(tmp_script_file)
   expect {
   "INVALID "  { exit 4 }
   timeout     { exit 4 }
   }
   EOF
   echo "spawned process status" $?
   rm -f $tmp_script_file
   echo "done"
  </code></pre>
  
  <p>Spawned script:</p>
  
  <pre><code> [Linux Dev:anr ]$ cat tmp_script
   exit 3
  </code></pre>
  
  <p>Execution of Expect script:</p>
  
  <pre><code> [Linux Dev:anr ]$ ./testexit.sh
   exit 3
   spawn /home/anr/tmp_script_temp.sh
   spawned process status 0
   done
  </code></pre>
  
  <p>Problem is I am unable to get the spawned exit return code to expect script. I want the exit code 3 of spawned script to main script and main script should be exit with exit code 3.</p>
  
  <p>Please help me to get the spawned exit code to main script.</p>