On Thu, Sep 20, 2012 at 3:43 AM, eryksun <eryk...@gmail.com> wrote:
> On Wed, Sep 19, 2012 at 2:47 PM, ashish makani <ashish.mak...@gmail.com> > wrote: > > > > I tried this > >>>> import os > >>>> os.system ("ssh remoteuser@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) >> try: >> 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.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor