我使用 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/