python - Cannot do "sudo su - postgres" with subprocess.call -
i try following command:
subprocess.call(['sudo', 'su - postgres'], shell=true)
or
subprocess.call(['sudo', 'su', '-', 'postgres'], shell=true)
in python2.7 (either ipython
manually writing line, or python myfile.py
being line part of code), , sudo usage information:
usage: sudo [-d level] -h | -k | -k | -v usage: sudo -v [-akns] [-d level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] usage: sudo -l[l] [-akns] [-d level] [-g groupname|#gid] [-p prompt] [-u user name] [-u user name|#uid] [-g groupname|#gid] [command] usage: sudo [-abehknps] [-c fd] [-d level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid] [var=value] [-i|-s] [<command>] usage: sudo -e [-akns] [-c fd] [-d level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file ...
i can run command in shell no problems @ all. both times same shell.
q: doing wrong?
from subprocess docs:
args required calls , should string, or sequence of program arguments. providing sequence of arguments preferred, allows module take care of required escaping , quoting of arguments (e.g. permit spaces in file names). if passing single string, either shell must true (see below) or else string must name program executed without specifying arguments.
therefore, list sequence. single command, place string, together, there no need have split:
subprocess.call(['sudo su - postgres'], shell=true)
Comments
Post a Comment