I am trying to execute a python script through subprocess
. First I tried to execute the python script present on my local machine through following code:
str = 'abc'
sub_result = subprocess.Popen([sys.executable,"./script.py"] + str)
this worked correctly. Now I am trying to execute the script present on remote machine through subprocess
. First I couldn't find any example on how to do it through subprocess.Popen()
like I did for local machine. I then tried to use subprocess.call()
in the following code but I am having issues with it:
str = 'abc'
sub_result = subprocess.call('ssh username@hostname python ./script.py' + str)
I get following error:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
What is the mistake I am doing and also how can I mention the password
in the ssh
command for connection?
UPDATE: Based on @musiphil's answer I modified my code and no I am using:
str = 'abc'
sub_result = subprocess.call(['ssh', 'username@hostname', 'python', './script.py'] + str)
But I get this error:
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
Permission denied, please try again.
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).