paramiko read stdout - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: paramiko read stdout (/thread-1138.html) |
paramiko read stdout - j.crater - Dec-07-2016 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 RE: paramiko read stdout - j.crater - Dec-08-2016 I got the answer I needed by adding this line: exit_code = stdout.read().decode('ascii').strip("\n") RE: paramiko read stdout - nilamo - Dec-08-2016 Thanks for sharing how you figured it out :) |