如何从另一台计算机 运行 一个 bash 脚本?

How to run a bash script from another computer?

我开发了一个 Python 应用程序,它需要调用存储在另一台计算机 (Raspberry Pi) 中的 bash 脚本。

我不需要获得任何 return 值或确认。

可行的方法是什么?

谢谢!

从 shell 你可以这样做:

ssh pi@theraspberrypi "./myscript"

到 运行 来自 Python 的 shell 命令:

import os
os.system("ssh pi@theraspberrypi ./myscript")

或者,按照下面 Eevee 的建议:

import subprocess
subprocess.call(['ssh pi@theraspberrypi ./myscript'], shell=True)

当然,您可能希望将 public 密钥放入 raspberry pi 的 authorized_keys 文件中,这样它就不会提示输入密码。