views:

21

answers:

1

I am trying to combine the output of stdout and stderr. My belief is that this can be done with the set_combine_stderr() of a Channel object.

This is what I am doing:

SSH = paramiko.SSHClient()
#I connect and everything OK, then:
chan = ssh.invoke_shell()
chan.set_combine_stderr(True)
chan.exec_command('python2.6 subir.py')
resultado = chan.makefile('rb', -1.)

However, I get the following error when I try to store the result (last line above, chan.makefile() ):

Error: Channel closed.

Any help would be greatly appreciated

A: 

@AaronMcSmooth: I am referring to the stdout and stderr of the computer I am connecting to (via SSH).

I ended up doing this:

stdin, stdout, stderr = ssh.exec_command(...)

output = stdin.read().strip() + stdout.read().strip()

For the purpose of my application, it doesn't matter to distinguish between stdout and stderr, but I don't think that's the best way to combine the two.

The code of SSHClient.exec_command() is (looking at paramiko's source 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

I am performing the same actions on the channel but receive the Channel is closed error.

DanielS