ssh - How to capture the output of executed command (python paramiko )? -


i executing commands , capture output of same.

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 ?                     # instance #1  stdin, stdout, stderr = ssh.exec_command("kill -9 1111") out = stdout.read() print out #prints nothing. expected doesn't capture if it's successful # print out # should print "-bash: kill: (1111) - no such process" , if doesn't exist  #--> instance #2 

in instance #1, why print stdout.read() , prints nothing ?

in instance #2, how capture such outputs/response ?

instance #1

out = stdout.read() print stdout.read() 

the first stdout.read() has consumed output second stdout.read() returns nothing.

instance #2

usually error messages print stderr should use stderr.read() error.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -