Remote command execution in python using paramiko that supports arbitrary input

I recently decided to use paramiko to develop a remote command execution tool.

It was very easy to setup initially and ran much faster than my existing pexpect implementation but it had a problem with sudo commands because they required the password to be provided as input.

I solved the problem by using a pseudo-terminal and by creating my own ChannelFile objects for stdin and stdout/stderr. The solution should be general enough to handle any case that requires simple input but it is not as flexible as pexpect. I hope that you find it useful.

Current Version

This is similar to the older version below but it handles more than 64KiB by eliminating the stdout buffer, the stdin buffer and using recv polling. It even does a silly check for input. That check could be expanded to make it behave more like pexpect but that is for another day.

Older Version

This version will not handle more than 64KiB of output. I am not sure why.

8 thoughts on “Remote command execution in python using paramiko that supports arbitrary input”

  1. Hello Joe!

    Thanks a lot for you code.
    I was debugging my code for the last two days untill I ran into your page…

    My code was missing the .get_pty() call

    Anyhow, thanks a lot for your help.



Leave a Reply