0

so I'm trying to get paramiko to actively print output in the ssh session i created, instead it seems to wait till the program is done and dumps all the output at once. tried a solution that is blocked out in my code that did not seem to work.

    # -*- coding: utf-8 -*-
"""
Created on Thu Aug 11 18:01:47 2022

@author: GigaGame
"""

import paramiko

hostnamefil ="192.168.0.120"
portfil =22
userfil="***"
passsfil="***"

def filterwheel():
    
    try:
        client=paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(hostnamefil,port=portfil,username=userfil,password=passsfil)
        while True:
            try:
                print("Welcome to the Filter Wheel")
                print("Type exit to quit the program.")
                cmd = "python3 ./Software/MTS/filter_wheel/fw102c_control.py"
                #cmd = input("$> ")
                if cmd == "exit": break
                stdin, stdout, stderr=client.exec_command(cmd)
                #sys.stdout.read(paramiko.Transport((hostnamefil, 22)).open_session().recv(1))
                print ("main:: Begin program..."
                "Residual System Status: startup"

                "Please address errors. Continue? (Y/N)")
                in1=input("$> ")
                if in1=="exit":break
                stdin.write(in1 + '\n')
                stdin.flush()
                print (stdout.read().decode())
                print (stderr.read().decode())
            except KeyboardInterrupt:
                break
        client.close()
    except Exception as err:
        print(str(err))
        
filterwheel()
Munix0
  • 1
  • 3
  • question is from 8 years ago and seems to be using ssh, pip wont install it. wondering if there is a more modern solution. – Munix0 Aug 12 '22 at 19:21
  • so i tried implementing the line_buffered def but it seems to do the same behavior when the python script runs on the ssh machine. ya its paramiko I'm using, someone said use sockets for the live stream aspect but I'm still wrapping my head around it. Guess I hope there is just a simple one liner to print the output from the python program over time and not in one large dump text as its doing. – Munix0 Aug 12 '22 at 19:58
  • i got it functioning, thanks for our help – Munix0 Aug 15 '22 at 18:29

0 Answers0