title: second "send" command in expect script is not waiting to finish the Output of first command
body: <p>I have a very small expect script . The flow is as follows</p>
  
  <ol>
  <li><code>ssh</code> to remote machine</li>
  <li>Execute a command and after executing the command you will be in a different prompt ( prompt name is <code>Enter cmd&gt;</code>.</li>
  <li>On the <code>Enter cmd&gt;</code> prompt, I need to run many commands</li>
  </ol>
  
  <p>Hence I designed this script</p>
  
  <pre><code>#!/usr/bin/expect
  
   set FULL_CMD { #cmd1 #cmd2 #cmd3  }
   puts "STARTING......."
  
   log_file myfile.log ;# &lt;&lt;&lt; === append output to a file
   spawn ssh tempuser\@dummyserver
   match_max  100000000
  
   expect "password:"
   send "temppasswd\r"
  expect  "*temp*"
   send "cd \/home\r"
   expect "*temp*"
  send "new cmd prompt\r"
  expect "Enter cmd&gt;"
  
  foreach tempcmd $FULL_CMD {
   send "${tempcmd} \r "
   expect -exact  "Enter cmd&gt;\r"
   send -- "\r"
  expect eof }
  
  send "q"
  send "exit\r"
  
  puts "I HAVE ENDED......."
  </code></pre>
  
  <p><strong>My problem:</strong> Actually the O/P of first command <code>cmd#1</code> is very long and I can see that the expect script is not waiting for the O/P of the first command complete and is sending the second command <code>cmd#2</code> after some time.</p>
  
  <p>This script works fine on systems where O/P of <code>cmd#1</code> is small, but on systems where the the O/P of <code>cmd#1</code> is very large (say 1000000 lines), it has trouble, i.e. it issues the first command <code>cmd#1</code> and the O/P follows, but before it get back to <code>Enter cmd&gt;</code> prompt, the script issues the second command <code>cmd#2</code></p>
  
  <p>How can I ensure that command <code>cmd#2</code> is sent only after the output of <code>cmd#1</code> completes?</p>