python - Subprocess module for remote command(s) -


i trying use subprocess module executing remote command. need execute program called 'upgrade' located on remote server. also, need use argument in call. here how tried that:

import subprocess p=subprocess.popen(['ssh', '15.36.77.1', './home/upgrade -u' ],stdin=subprocess.pipe, stdout=subprocess.pipe,stderr=subprocess.pipe, shell=true) stdout,stderr=p.communicate(input='\n') 

when try execute command , return code form it, 255, means command failed. me issuse? no third part libraries should used. sorry bad english.

i think you're problem when using shell=true execute give subprocess.popen string. 2 ways , without shell=true follows:

subprocess.call(["ls", "-l"])  subprocess.call("exit 1", shell=true) 

so in case string need give popen is:

['ssh 15.36.77.1 ./home/upgrade -u'] 

or can remove shell=true make command:

p=subprocess.popen(['ssh', '15.36.77.1', './home/upgrade -u' ],                    stdin=subprocess.pipe, subprocess.pipe,stderr=subprocess.pipe) 

note using shell=true not recommended can potential security hazard if asking intput command line. see example given in documentation:

https://docs.python.org/2/library/subprocess.html#frequently-used-arguments

p.s. english great!


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -