title: How to capture the output of executed command (python paramiko )?
body: <p>I am executing certain commands and would like to capture the output of the same.</p>
  
  <pre><code>import paramiko
  
  ssh = paramiko.SSHClient()
  ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  ssh.connect(ip,username="username",password="pwd")
  stdin, stdout, stderr = ssh.exec_command("whoami")
  out = stdout.read()
  print out           # prints username
  print stdout.read() # prints nothing, why is it so ?
                      # Instance #1
  
  stdin, stdout, stderr = ssh.exec_command("kill -9 1111")
  out = stdout.read()
  print out #prints nothing. expected as it doesn't capture if it's successful
  # print out # should print "-bash: kill: (1111) - No such process" , if it doesn't exist 
  #--&gt; Instance #2
  </code></pre>
  
  <p>In Instance #1, why print stdout.read() , prints nothing ?</p>
  
  <p>In Instance #2, How to capture such outputs/response ?</p>