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

Piet van Oostrum piet at vanoostrum.org
Thu Sep 20 13:45:31 EDT 2012


Chris Rebert <clp2 at rebertia.com> writes:

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

You will still need to worry about escaping because on the remote end
you invoke ssh which is a shell. The obvious call:

subprocess.call(["ssh", "remoteuser at remote", "python", "remote.py", "arg
1", "arg 2", "arg 3"])

won't work because ssh will break up the "arg n" strings. You need to
use  "'arg n'" or put the whole python command in a string like:

"python TEST/testargs.py 'arg 1' 'arg 2' 'arg 3'"
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list