擅长:python、mysql、java
<p>@AaronMcSmooth:我指的是我正在连接的计算机的stdout和stderr(通过SSH)。</p>
<p>我最后这样做了:</p>
<pre><code>stdin, stdout, stderr = ssh.exec_command(...)
output = stdin.read().strip() + stdout.read().strip()
</code></pre>
<p>就我的应用程序而言,区分stdout和stderr并不重要,但我不认为这是将两者结合起来的最佳方式。</p>
<p><code>SSHClient.exec_command()</code>的代码是(查看paramiko的源代码):</p>
<pre><code>def exec_command(self, command, bufsize=-1):
chan = self._transport.open_session()
chan.exec_command(command)
stdin = chan.makefile('wb', bufsize)
stdout = chan.makefile('rb', bufsize)
stderr = chan.makefile_stderr('rb', bufsize)
return stdin, stdout, stderr
</code></pre>
<p>我正在通道上执行相同的操作,但接收到通道关闭错误。</p>