可能與https://github.com/paramiko/paramiko/issues/109相關。
我也遇到了這個問題,是由於stdout.channel.eof_received =import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("1.1.1.1", username="root", password="pass")
stdin, stdout, stderr = client.exec_command("service XXX start")
stdin,stdout和stderr保持打開狀態。>>> print stdin
>>
>>> print stdout
>>
>>> print stderr
>>
未收到EOF。>>> print stdin.channel.eof_received
0
等待超時,強制stdout.channel.close(),然後執行stdout.read():>>> timeout = 30
>>> import time
>>> endtime = time.time() + timeout
>>> while not stdout.channel.eof_received:
... sleep(1)
... if time.time() > endtime:
... stdout.channel.close()
... break
>>> stdout.read()
'Starting XXX: n[ OK ]rProgram started . . .n'
>>>
我使用:Python 2.6.6
paramiko (1.15.2)
希望這有幫助。