本文介绍了Paramiko SSH exec_command(shell 脚本)在完成前返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Paramiko 从远程 Linux 机器启动了一个 shell 脚本.启动 shell 脚本并执行命令 make -j8
.但是 exec_command
在 make 完成之前返回.
I launch a shell script from a remote Linux machine using Paramiko. The shell script is launched and execute a command make -j8
. However the exec_command
returns before the completion of the make.
如果我在本地机器上启动脚本,它会正确执行.
If I launch the script on the local machine it executes correctly.
有人可以向我解释这种行为吗?
Could someone explain me this behaviour?
推荐答案
您需要等待应用程序完成,exec_command 不是阻塞调用.
You need to wait for application to finish, exec_command isn't a blocking call.
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"
这篇关于Paramiko SSH exec_command(shell 脚本)在完成前返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!