Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

user interface - How can I use python to execute a .sh file on my raspberry pi from my gui app (using VS code) once the pi is connected?

The following two functions are part of my full code (built a gui app to onboard our units we manufacture and sell for keypads) that help us set up and test the units. Right now I have it where the gui allows me to map the network (search all IP), connect to the device, and end the program. What I need to do, is properly execute the .sh file "commands.sh" on the raspi.

def raspi_connecter(): 
    for n in range(1, 255):
        server_ip="10.0.0.{0}".format(n)
        subprocess.Popen('ssh' + ' ' + 'dev@' + server_ip, shell= True) 
def keypad_tests():
    if raspi_connecter:
        cmd = ('./commands.sh')
        p = paramiko.SSHClient()
        p.set_missing_host_key_policy(paramiko.AutoAddPolicy())   
        stdin, stdout, stderr = p.exec_command(cmd)
        opt = stdout.readlines()
        opt = "".join(opt)
        print(opt)

The error message I receive is this: Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/init.py", line 1883, in call return self.func(*args) File "/Users/myname/Desktop/projectfolder/gui_macOS.py", line 128, in keypad_tests stdin, stdout, stderr = p.exec_command(cmd) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/client.py", line 508, in exec_command chan = self._transport.open_session(timeout=timeout) AttributeError: 'NoneType' object has no attribute 'open_session'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...