Paramiko SSH exec_command(脚本)返回结果未完成
我在一台远程的Linux机器上用Paramiko启动了一个shell脚本。这个脚本会执行一个命令make -j8
。但是,exec_command
在这个命令还没执行完的时候就返回了。
如果我在本地机器上启动这个脚本,它就能正确执行。
有人能解释一下这是为什么吗?
1 个回答
30
你需要等应用程序完成,因为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"