【发布时间】:2015-12-09 14:19:17
【问题描述】:
我在 Paramiko 中编写了这段代码:
ssh = SSHClient()
ssh.set_missing_host_key_policy(AutoAddPolicy())
ssh.connect(hostname, username=user, password=passwd, timeout=3)
session = ssh.invoke_shell()
session.send("\n")
session.send("echo step 1\n")
time.sleep(1)
session.send("sleep 30\n")
time.sleep(1)
while not session.recv_ready():
time.wait(2)
output = session.recv(65535)
session.send("echo step 2\n")
time.sleep(1)
output += session.recv(65535)
我正在尝试在我的 Linux 服务器上执行更多命令。问题是我的 Python 代码没有等待完成执行命令,例如,如果我尝试执行 sleep 30,Python 不会等待 30 秒来完成执行命令。怎样才能解决这个问题?我尝试了while recv_ready(),但它仍然没有等待。
【问题讨论】: