Python Forum

Full Version: paramiko read stdout
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I have a simple function that uses SSH via paramiko module. For example, if I have a line:
stdin, stdout, stderr = client.exec_command("echo 0")
I would expect stdout to be "0", instead I get:

b'0\n'
<paramiko.ChannelFile from <paramiko.Channel ...... etc>

Is there a simple way for me to only get the "clean" stdout output returned from exec_command? I know I can parse the present output (to obtain only 0 in this particular case), but I believe there must be another solution by paramiko's design. Thank you, JC
I got the answer I needed by adding this line:
exit_code = stdout.read().decode('ascii').strip("\n")
Thanks for sharing how you figured it out :)