[Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .
ashish.makani at gmail.com
Thu Sep 20 14:17:43 CEST 2012
On Thu, Sep 20, 2012 at 3:43 AM, eryksun <eryksun at gmail.com> wrote:
> On Wed, Sep 19, 2012 at 2:47 PM, ashish makani <ashish.makani at gmail.com>
> > I tried this
> >>>> import os
> >>>> os.system ("ssh remoteuser at remote python remote.py arg1 arg2 arg3")
> > This worked, but if the arguments i tried to pass, had spaces, i was not
> > able to 'escape' the spaces.
> Presuming "remote" has an SSH server running, and that a firewall
> isn't blocking port 22, and that you've enabled logging in without a
> password (i.e. ssh-keygen), try the following:
> import sys
>> import subprocess
>> user = remoteuser
>> hostname = remote
>> cmd = 'python remote.py "%s" "%s" "%s"' % (arg1, arg2, arg3)
>> out = subprocess.check_output(['ssh', '%s@%s' % (user,
>> hostname), cmd])
>> except subprocess.CalledProcessError as e:
>> print >>sys.stderr, str(e) # handle/log the error, retry
This worked like a charm.
Thank you so much.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor