I think os.environ.copy()
is better if you don’t intend to modify the os.environ for the current process:
import subprocess, os
my_env = os.environ.copy()
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
More Related Contents:
- How to use subprocess popen Python [duplicate]
- Subprocess.Popen: cloning stdout and stderr both to terminal and variables
- Popen waiting for child process even when the immediate child has terminated
- Python popen command. Wait until the command is finished
- How can I specify working directory for popen
- Intercepting stdout of a subprocess while it is running
- Python subprocess.Popen() error (No such file or directory)
- Popen with conflicting executable/path
- How do I get ‘real-time’ information back from a subprocess.Popen in python (2.5)
- subprocess.Popen() error (No such file or directory) when calling command with arguments as a string
- How to write to stdout AND to log file simultaneously with Popen?
- How do I get all of the output from my .exe using subprocess and Popen?
- link several Popen commands with pipes
- Python subprocess and user interaction
- Keep a subprocess alive and keep giving it commands? Python
- Launch a shell command with in a python script, wait for the termination and return to the script
- How to get output from subprocess.Popen(). proc.stdout.readline() blocks, no data prints out
- How to run a background process and do *not* wait?
- real time subprocess.Popen via stdout and PIPE
- What’s the difference between subprocess Popen and call (how can I use them)?
- python subprocess Popen environment PATH?
- How do I eliminate Windows consoles from spawned processes in Python (2.7)? [duplicate]
- How can I specify working directory for a subprocess
- Bash style process substitution with Python’s Popen
- Why does subprocess.Popen() with shell=True work differently on Linux vs Windows?
- How to do multiple arguments with Python Popen?
- subprocess.wait() not waiting for Popen process to finish (when using threads)?
- Opening a process with Popen and getting the PID
- subprocess.Popen in different console
- What is the subprocess.Popen max length of the args parameter?