Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

Chris Rebert clp2 at rebertia.com
Thu Sep 20 12:19:12 EDT 2012


On Wed, Sep 19, 2012 at 12:50 PM, ashish <ashish.makani at gmail.com> wrote:
<snip>
> 2. I have a python script, local.py, running on 'local' which needs to pass arguments ( 3/4 string arguments, containing whitespaces like spaces, etc ) to a python script, remote.py running on 'remote' (the remote machine).
<snip>
> 3. Has anybody been able to do this using os.system ?
>
> 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.

Use the `subprocess` module instead (with shell=False). You then won't
need to worry about escaping.
http://docs.python.org/library/subprocess.html

Cheers,
Chris



More information about the Python-list mailing list