Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
paramiko read stdout
#1
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
Reply
#2
I got the answer I needed by adding this line:
exit_code = stdout.read().decode('ascii').strip("\n")
Reply
#3
Thanks for sharing how you figured it out :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [subprocess] Why stdout sent to stderr? Winfried 3 418 Jan-26-2024, 07:26 PM
Last Post: snippsat
  Performance options for sys.stdout.writelines dgrunwal 11 2,995 Aug-23-2022, 10:32 PM
Last Post: Pedroski55
  changing stdout and stderr Skaperen 4 2,645 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  Get stdout of a running process yok0 0 2,975 Aug-20-2020, 10:12 AM
Last Post: yok0
  will with sys.stdout as f: close sys.stdout? Skaperen 9 4,495 Nov-03-2019, 07:57 AM
Last Post: Gribouillis
  Add stdout to text file maxtimbo 3 3,099 Feb-05-2019, 12:53 AM
Last Post: maxtimbo
  stdout buffering Skaperen 5 4,656 Jun-12-2018, 06:14 AM
Last Post: Skaperen
  stdout Skaperen 0 2,611 Mar-19-2018, 01:23 AM
Last Post: Skaperen
  Subprocess - get only first few lines of stdout j.crater 3 17,017 May-30-2017, 08:12 PM
Last Post: snippsat
  Write stdout to file mcmxl22 3 4,948 Jan-01-2017, 05:03 PM
Last Post: mcmxl22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020