I need to interact with a python script at a particular time, when prompted to by a printed line in the Python script. For an even more minimal example, I'm just trying to get the output of print() as the python script is being executed. Currently I can only get it as it's completed.
My server side python_script.py is:
count = 0
while True:
count += 1
print(count)
Client side I have:
....
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=22, username=user, password=passwd, look_for_keys=False, allow_agent=False)
command = "python C:\\users\\...\\desktop\\python_script.py "
(stdin, stdout, stderr) = ssh.exec_command(command)
while True:
a = stdout.readlines()
print(a)
The result is just a blank, unending execution in the client's terminal. What I want to see is a Python array of consecutive numbers (or anything really).
I am able to get an stdout ONLY when my scripts finish executing, but this is not helpful when I need to respond to the scripts. I don't have a good enough understanding of the issue, or how to get stdout to buffer mid script, in order to fix this.