我要在另一台机器上运行一个python脚本和另一个脚本。第一个脚本应该从图像处理线程获取数据,将它们发送到第二个脚本,并在所有操作都在运行时从第二个脚本获取stdout。在
我使用spur库成功地通过ssh运行了一个程序。我可以向该程序发送数据,但无法在程序仍在运行时获取其标准输出(必须等待进程完成):
import spur
# Open SSH connection
print("Connection ...")
ssh = spur.SshShell(
hostname="host",
username="name",
password="pswd",
missing_host_key=spur.ssh.MissingHostKey.accept,
)
# start program in a process (on the second machine)
process = ssh.spawn(["sudo", "python3.6", "program.py"])
c=0
while True:
print("send data : " + str(c))
process.stdin_write(str(c))
c+=1
我试着用另一种方法找到任何信息,也许是用另一个包(比如paramiko?)但没有找到类似的应用程序。在
有人知道这方面的信息吗?我应该用别的东西吗?在
谢谢
pexpect适用于这种情况:
https://pexpect.readthedocs.io/en/stable/api/pxssh.html
https://github.com/pexpect/pexpect/blob/master/examples/monitor.py
相关问题 更多 >
编程相关推荐