title: How to turn off stderr in Expect script or stop "Connection to ... closed" message after exiting?
body: <p>So I have been trying to learn bash scripting with expect and I'm running into an annoying problem where even after I turn off output by setting log_user to 0, the logout message for when I exit the ssh server is still printed as "logout
  Connection to blah.blah.blah closed". Going the hackish way and issuing the exit command inside the script to expect is undesirable, and neglects to print a new line in the terminal, leaving an unsightly terminal prompt behind. How do I suppress or turn off this connection closed message in my expect script? Here's a template of the code for my expect script:</p>
  
  <pre><code>#!/usr/bin/expect -f
  #-f flag tells expect to read commands from file
  
  # Set Password Prompt and Password
  set PASSP "password:"
  set PASSW "your_password_here\n"
  
  # Set SFTP Prompt 
  set SFTP "sftp&gt; "
  
  # Set Remote Prompt and Project Directories
  # The GL server is super weird, so make sure RPROMPT ends in the
  # name of the project compilation directory and PROJDIR is the 
  # relative path (from home but without the tilde) of the main 
  # project directory.
  
  set RPROMPT "projdir_here]"
  set PROJDIR "path_to_projdir_here"
  
  # Set SSH Address
  set ADDRESS your_username_here@your_address_here
  
  # Annoying long output turned off
  log_user 0
  
  send_user "Logging in...\n"
  
  spawn sftp $ADDRESS
  expect $PASSP
  send $PASSW
  
  expect $SFTP
  send_user "Uploading necessary files...\n"
  
  send "cd $PROJDIR\n"
  expect $SFTP
  send "put *.cpp .\n"
  expect $SFTP
  send "put *.h .\n"
  expect $SFTP
  send "put Makefile .\n"
  expect $SFTP
  send "exit\n"
  
  spawn ssh $ADDRESS
  expect $PASSP
  send $PASSW
  expect "]"
  send "cd $PROJDIR\n"
  
  expect $RPROMPT
  send_user "Cleaning remote directory...\n"
  
  send "make clean\n"
  
  # Output turned on temporarily so compiler feedback can be determined
  expect $RPROMPT
  log_user 1
  send_user "Compiling on server...\n"
  
  send "make\n"
  
  # Turn off output and submit (this assumes that your makefile has a 'submit'
  # target with the command to submit your file there)
  expect $RPROMPT
  log_user 0
  send_user "\nSubmitting Requisite Files...\n"
  
  send "make submit\n"
  
  expect $RPROMPT
  send_user "Quitting...\n"
  
  # I can't figure out how to turn off stderr in expect so that an annoying 'connection closed' 
  # message is printed even the log_user has been set to 0
  send "logout\n"
  
  # Transfer control to user
  interact
  </code></pre>
  
  <p>You can see that at the end of the program, before I use the interact command, that the offending message is printed after "logout\n" is sent and the connection to the server is closed. This happens despite log_user being set to 0 above. How on earth do I turn off stderr output inside my script? I've even looked at the manual pages for expect at <a href="http://www.tcl.tk/man/expect5.31/expect.1.html" rel="nofollow">expect man page</a> but there didn't seem to be much useful there. I don't understand how to turn off stderr inside an expect script so that this message isn't printed, help would be much appreciated! I really just want the script to be quiet when I'm logging out. Because it's pretty obvious that I issued a logout command, I'm not sure why this output goes to stderr. Is there a command in ssh that won't output a "Connection to...closed" message when the user exits? It would be better if I could just pipe stderr to oblivion or suppress it somehow. The normal ways don't seem to work because this is an expect script.</p>