title: How to wait for a process to complete using tcl-expect
body: <p>I am writing a script using expect in which I have to rlogin to some host &amp; after that I need to send some commands. Now I want to exit to that host and relogin again to some other host and send some commands. But the run of my script is not waiting for first host to complete its jobs and exit instead it sends other commands in between the previous process.
  How can I achieve this using expect please guide? </p>
  
  <p>Sample code is as follow :</p>
  
  <pre><code>#!/usr/local/bin/expect -f
  
  spawn rlogin host1
  expect "%"
  send "source xyz.csh\r"
  send "exit\r"
  expect "%"
  
  spawn rlogin host2
  some set of commands
  </code></pre>