title: Run expect spawned commands one after the another
body: <p>I have written an expect script which I am calling from my bash script, which removes the content in the directories, copies the jar and extracts it. I am doing it through expect script shown below:</p>
  
  <p>I have used sleep and wait between the process and nothing helps. I do not get the desired output as expected. Please check the script is fairly simple, it removes content inside the directory, created one, add jar and tries to extract it.</p>
  
  <pre><code>set timeout -1
  set PASS [lindex $argv 0];
  set DIRECTORY [lindex $argv 1];
  set FOLDER_NAME [lindex $argv 2];
  set WAR_PATH [lindex $argv 3];
  set WAR_NAME [lindex $argv 4];
  spawn sudo rm -rf $DIRECTORY/$FOLDER_NAME
  expect "Password:"
  send $PASS\r
  spawn sudo mkdir $DIRECTORY/$FOLDER_NAME
  expect "Password:"
  send $PASS\r
  spawn sudo cp $WAR_PATH $DIRECTORY/$FOLDER_NAME
  expect "Password:"
  send $PASS\r
  spawn sudo jar -xf $DIRECTORY/$FOLDER_NAME/$WAR_NAME
  expect "Password:"
  send $PASS\r
  set timeout -1
  expect eof
  exit 0
  
  </code></pre>
  
  <p>Please help me so that this process is completed one after another without any problem. Thanks for your help.</p>