title: Expect script reading commands from file
body: <p>I'm trying to write an expect script that reads commands from a file and executes them, as explained in <a href="https://stackoverflow.com/questions/17662391/read-file-into-string-and-do-a-loop-in-expect-script">this topic</a>. Here is my script called <code>script.sh</code>:</p>
  
  <pre><code>#!/usr/bin/expect
  
  set f [open "script_cmds.txt"]
  set cmds [split [read $f] "\n"]
  close $f
  
  foreach cmd $cmds {
      spawn cmd 
  }
  
  expect eof
  close
  </code></pre>
  
  <p>And the file <code>script_cmds.txt</code>, situated in the same folder, looks like this:</p>
  
  <pre><code>mkdir cmdlisttest1
  mkdir cmdlisttest2
  </code></pre>
  
  <p>To compile and run the script on cygwin I use</p>
  
  <pre><code>chmod +x script.sh
  d2u script.sh
  ./script.sh
  </code></pre>
  
  <p>The output I get reads</p>
  
  <pre><code>spawn cmd
  spawn cmd
  Microsoft Windows [Version 6.1.7601]
  Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
  
  C:\cygwin\home\user&gt;
  </code></pre>
  
  <p>and then it stops there without exiting. The folders <code>cmdlisttest1</code> and <code>cmdlisttest2</code> are not created.</p>
  
  <p>I'm fairly new to expect scripts; can anyone spot the mistake(s)?</p>