Execute a command on remote machine in python

Roy Smith roy at panix.com
Tue Nov 15 09:20:50 EST 2011


In article <mailman.2728.1321366254.27778.python-list at python.org>,
 Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Nov 15, 2011 at 11:04 PM, Roark <suhasrm at gmail.com> wrote:
> > Hi,
> >
> > I want to execute a windows command within python script from a client
> > machine on a remote target server, and would want the output of the
> > command written in a file on client machine. What is the way it could
> > be achieved.
> 
> This looks like a job for SSH.

You might also want to look at fabric (http://fabfile.org).  It's a nice 
python library for remote command execution built on top of SSH.

A more general answer is that, yes, SSH is the right thing to be looking 
at for your basic connectivity, data transport and remote command 
execution.  But trying to deal with raw SSH will drive you batty.  
Something like fabric, layered on top of SSH, will make things a lot 
easier.



More information about the Python-list mailing list