title: TCL / Expect - After Interact, expect_user doesn't echo
body: <p>So I have a simple script that logs into a network device, and then interacts allowing users to call various macros. I have an example below- the user is in the device, hits "!p" and then the script wants the user to input a command.</p>
  
  <p>all works fine, except the program isn't echoing what the user types so it's impossible for them to correct mistypes. </p>
  
  <p>The solution I have currently is <code>stty echo</code> before <code>expect_user</code> and <code>stty -echo</code> after. But in this solution, backspaces and arrow key presses are captured so the user still cannot correct their mistype.  </p>
  
  <p>I'm not exactly sure how to fix this, but what I assume is happening is the spawned program has control of STDOUT so when expect_user is called, it's in the background.</p>
  
  <pre><code>set hostname 10.0.0.1
  set password 1234qwer
  
  spawn ssh -o StrictHostKeyChecking=no $hostname
  expect {
          "assword:" {
                          send "$password\r"
                          expect "#"
          }
  }
  interact {
          "!p" {
                  send_user "\nInput command: "
                  expect_user -re "(.*)\r" {
                          puts "\n$expect_out(1,string)"
                  }
          }
  }
  </code></pre>