title: Expect crashing running exec command
body: <p>I have an expect script that performs an <code>exec</code> that can take some time (around 5 mins).</p>
  
  <p>I have copied the script below and also the output from running the script.</p>
  
  <p>If the script was timing out, I would have thought "timeout" was printed to std out?</p>
  
  <p>Any pointers will be appreciated!</p>
  
  <pre><code>expect &lt;&lt;EOF
     cd /home/vagrant/cloudstack
     # 20 mins timeout for jetty to start and devcloud to be provisioned
     set timeout 1200
     match_max 1000000
  
     set success_string "*Started Jetty Server*"
  
     spawn "/home/vagrant/cloudstack_dev.sh" "-r"
     expect {
       -re "(\[^\r]*\)\r\n" 
       {
         set current_line \$expect_out(buffer)
  
         if { [ string match "\$success_string" "\$current_line" ] } {
            flush stdout
            puts "Started provisioning cloudstack."
  
            # expect crashes executing the following line:
            set exec_out [exec /home/vagrant/cloudstack_dev.sh -p]
  
            puts "Finished provisioning cloudstack. Stopping Jetty."
            # CTRL-C
            send \003
            expect eof
         } else { 
            exp_continue 
         }
       }
       eof { puts "eof"; exit 1; }
       timeout { puts "timeout"; exit 1; }
     }
  EOF
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>...
  2014-03-14 06:44:08 (1.86 MB/s) - `/home/vagrant/devcloud.cfg' saved [3765/3765]
  
  + python /home/vagrant/cloudstack/tools/marvin/marvin/deployDataCenter.py -i /home/vagrant/devcloud.cfg
  + popd
  + exit 0
      while executing
  "exec /home/vagrant/cloudstack_dev.sh -p"
      invoked from within
  "expect {
       -re "(\[^\r]*\)\r\n" 
       {
         set current_line $expect_out(buffer)
  
         if { [ string match "$success_string" "$current_line" ]..."
  </code></pre>
  
  <p>The function that gets run inside the cloudstack-dev.sh:</p>
  
  <pre><code>function provision_cloudstack () {
  
     echo -e "\e[32mProvisioning Cloudstack.\e[39m"
  
     pushd $PWD
     if [ ! -e $progdir/devcloud.cfg ]
     then
        wget -P $progdir https://github.com/imduffy15/devcloud/raw/v0.2/devcloud.cfg
     fi
     python /home/vagrant/cloudstack/tools/marvin/marvin/deployDataCenter.py -i $progdir/devcloud.cfg
     popd
  }
  </code></pre>
  
  <p>From the Expect output, it seems as though the function is being run ok.</p>