title: stdout stream redirect in expect scripts
body: <p>I have the following bash script which wraps an expect script (in here-document form):</p>
  
  <pre><code>#!/bin/bash
  
  PASSWORD_MYSQL_ROOT=root
  
  expect &lt;&lt;- DONE
    set timeout -1
    spawn mysqldump --all-databases --user=root --password --protocol=TCP --host=localhost --verbose &gt; somebackupfile.sql
    expect "*?asswor?:*"
    send -- "$PASSWORD_MYSQL_ROOT\r"
    expect eof
  DONE
  </code></pre>
  
  <p>When I execute this script, I get the following output:</p>
  
  <pre><code>spawn mysqldump --all-databases --user=root --password --protocol=TCP --host=localhost --verbose &gt; somebackupfile.sql
  Usage: mysqldump [OPTIONS] database [tables]
  OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
  OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
  For more options, use mysqldump --help
  send: spawn id exp4 not open
      while executing
  "send -- "root\r""
  </code></pre>
  
  <p>So something didn't work right.</p>
  
  <p>After some try and error, I found out that the stdout stream redirect <code>&gt; somebackupfile.sql</code> is the culprit -- the script works once this redirect is removed.</p>
  
  <p>So I am wondering: How do I use stream redirection in expect scripts?</p>