如何将EOF发送到paramiko的stdin?

Ale*_*dru 5 python stdin paramiko eof

我想通过ssh执行一些程序并从文件中重定向其输入.以下代码的行为:

channel.exec_command('cat')
with open('mumu', 'r') as f:
    text = f.read()
    nbytes = 0
    while nbytes < len(text):
        sent = channel.send(text[nbytes:])
        if sent == 0:
            break
        nbytes += sent
Run Code Online (Sandbox Code Playgroud)

应该等同于(假设公钥验证):

 ssh user@host cat < mumu
Run Code Online (Sandbox Code Playgroud)

然而,应用程序挂起等待更多输入.我认为这是因为stdin流永远不会关闭.我怎么做?

小智 5

在频道上呼叫shutdown()(或shutdown_write()).