17

我使用 Paramiko 从远程 Linux 机器启动一个 shell 脚本。启动 shell 脚本并执行命令make -j8。但是在exec_command制作完成之前返回。

如果我在本地机器上启动脚本,它会正确执行。

有人可以向我解释这种行为吗?

4

1 回答 1

28

您需要等待应用程序完成, exec_command 不是阻塞调用。

print now(), "before call"
stdin, stdout, sterr = ssh.exec_command("sleep(10)")
print now(), "after call"
channel = stdout.channel
print now(), "before status"
status = channel.recv_exit_status()
print now(), "after status"
于 2010-07-09T19:07:57.900 回答