python - Paramiko SSH exec_command(shell脚本)在完成前返回

标签 python ssh paramiko

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

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

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

最佳答案

您需要等待应用程序完成,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"

关于python - Paramiko SSH exec_command(shell脚本)在完成前返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3215727/

相关文章:

python - 为什么 paramiko 偶尔会引发异常?

python - 从 python 数据框创建嵌套的 JSON

python - 取带有掩码元素的 numpy ndarray 的平均值

python - 如何在定义指示返回的非典型对象的函数期间创建提示?

java - 尝试连接到 Symantec NetBackup 时 JSch 中出现 "Algorithm negotiation fail"错误 - 远程抓取报告

Python:尝试通过 SSH 执行命令时 Paramiko 挂起

python - 执行命令后 SSH session 不返回 o/p

docker - 使用来自 docker 的本地 ssh 端口转发

php - 使用 phpseclib Interactive shell 显示超过 17 行

Python 的 paramiko 带线程,奇怪的延迟