title: Python paramiko script, problems reading output during exec_command()
body: <p><strong>Background</strong>:
  I am using python and paramiko to automate the process I go through everytime I have to hand in a program for a class.  We use a command called "handin" to submit source code, but this must be done from a school computer.  So when I submit code from home, I have to: sftp into school servers, put the files in a dir, ssh into school computer, use 'handin' command</p>
  
  <p>I can successfully put files onto the school machines.  The problem occurs when I try to use exec_command('handin my files') and then read the output to determine the next action.</p>
  
  <p>so I have</p>
  
  <pre><code>try:
     (stdin, stdout, stderr) = client.exec_command(s)
  except:
     print 'whoops'
     sys.exit()
  print stdout.readlines()
  </code></pre>
  
  <p>But this causes a deadlock for some reason, the script appears to be doing nothing and I have to eventually kill the entire process (ctrl+c doesnt work).  Im not sure if exec_command is not completing correctly (even though it is getting out of the try/catch block) or if im having network problems or what.</p>
  
  <p>Any ideas? </p>
  
  <p>update:</p>
  
  <p>The problem is with interacting with the handin command during execution.  After executing the command, handin may or may not still be running.  If its the first time submitting it says success, blah blah, and finishes executing. All is well. But if I am re-submitting I have to authorize an overwrite (stdin.write('y')) for each file.</p>
  
  <p><strong>TL/DR:</strong></p>
  
  <p>How do I check if a exec_command() is still running, waiting for input, and readline() from stdout accordingly?</p>