1import subprocess, os
2my_env = os.environ.copy()
3my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
4subprocess.Popen(my_command, env=my_env)
1try:
2 subprocess.check_output(...)
3except subprocess.CalledProcessError as e:
4 print(e.output)
5