0

so i have created a paramiko ssh code that will ssh into a begalbone black, but when i go to run a python script in the interface it goes into limbo without any output, the python program on the begalbone is expecting user input. does anyone know how to get it to output the python programs output and receive input from the user?

i tried someones one liner that is blocked out as it did not help much, it seems to not locate the file.

this is the code i have so far

import paramiko import time

hostname ="192.168.0.120" port =22 user="****" passs="****"

client=paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname,port=port,username=user,password=passs)
#stdout = client.exec_command('python3 -c "exec(\\"' + open('fw102c_control.py','r').read().encode('base64').strip('\n') + '\\".decode(\\"base64\\"))"' )[1]
while True:
    try:
        cmd = input("$> ")
        if cmd == "exit": break
        stdin, stdout, stderr=client.exec_command(cmd)
        print ("stderr: ", stderr.readlines())
        print ("pwd: ", stdout.readlines())
        print (stdout.read().decode())
        print (stderr.read().decode())
    except KeyboardInterrupt:
        break
client.close() except Exception as err:
print(str(err))
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Munix0
  • 1
  • 3
  • The line commented out is something I tried that did not work. in the try statement is where the exec_command is implemented that is given by user input. there is no problem putting commands in and getting output until i attempt to run a python program, then all IO seems to cease, python ssh is still running but i cant do anything. I have used moba x to verify the python program indeed works, the issue is i cant seem to get output from the device when a python script is used. today im going to try and make a few simple scripts and see if its the script im implementing itself that is the prob. – Munix0 Aug 11 '22 at 13:45
  • i have found that it seems to hang up when the user is requested to give input in the ssh client to the begalbone – Munix0 Aug 11 '22 at 13:51
  • hell, thanks for that man, got it runnin. still didn't print the output of the question but i have another work around for it. – Munix0 Aug 11 '22 at 15:50
  • new issue, when I am reading the stout it seems to lag output until the python program is done, is there a way to get live feed of what is processing, some of the begalbone blacks consistently output data and it would be nice to see the output live. – Munix0 Aug 11 '22 at 21:56

0 Answers0