I try the following command:
subprocess.call(['sudo', 'su - postgres'], shell=True)
or
subprocess.call(['sudo', 'su', '-', 'postgres'], shell=True)
in Python2.7 (either by ipython manually writing the line, or python myfile.py being the line as part of the code), and get the 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 the command in the shell with no problems at all. Both times it is the same shell.
Q: What am I doing wrong?
subprocess.call(['sudo su - postgres'], shell=True)