Created
July 17, 2014 09:04
-
-
Save smurn/4d45a51b3a571fa0d35d to your computer and use it in GitHub Desktop.
Monkey patch for paramiko issue 291
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Add binary-mode options to SSHClient.exec_command(...) for binary stdout, stderr channels. | |
See: https://github.com/paramiko/paramiko/issues/291 | |
""" | |
import paramiko | |
def _patched_exec_command(self, | |
command, | |
bufsize=-1, | |
timeout=None, | |
get_pty=False, | |
stdin_binary=True, | |
stdout_binary=False, | |
stderr_binary=False): | |
chan = self._transport.open_session() | |
if get_pty: | |
chan.get_pty() | |
chan.settimeout(timeout) | |
chan.exec_command(command) | |
stdin = chan.makefile('wb' if stdin_binary else 'w', bufsize) | |
stdout = chan.makefile('rb' if stdin_binary else 'r', bufsize) | |
stderr = chan.makefile_stderr('rb' if stdin_binary else 'r', bufsize) | |
return stdin, stdout, stderr | |
paramiko.SSHClient.exec_command = _patched_exec_command | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should lines 25 and 26 be using
stdout_binary
andstderr_binary
, respectively, rather than all using the samestdin_binary
flag ?