title: How to capture expect output using spawn and sftp under solaris
body: <p>I am using expect to spawn a sftp session as follows:</p>
  
  <p>(lots of code snipped for clarity, and yes I understand the risks...)</p>
  
  <pre><code>#!/opt/csw/bin/expect -f
  
  &lt;snip&gt;
  
  spawn sftp $user@$host 
  
  set rez [connect $passw]
  if { $rez == 0 } {
    send "cd $location\r"
    set timeout -1
    send "ls -l\r" 
    send "quit\r"
    expect eof
    exit 0
  }
  puts "\nError connecting to server: $host, user: $user and password: $passw!\n"
  exit 1
  </code></pre>
  
  <p>This works just fine.  </p>
  
  <p>My specific question is how to I capture the results of the <strong>send "ls -l\r"</strong> command in a file.</p>