Fix Python – How can I specify working directory for popen

Is there a way to specify the running directory of command in Python’s subprocess.Popen()?
For example:
Popen(‘c:\mytool\tool.exe’, workingdir=’d:\test\local’)

My Python script is located in C:\programs\python
Is is possible to run C:\mytool\tool.exe in the directory D:\test\local?
How do I set the working directory for a sub-process?

Fix Python – Python subprocess/Popen with a modified environment

I believe that running an external command with a slightly modified environment is a very common case. That’s how I tend to do it:
import subprocess, os
my_env = os.environ
my_env[“PATH”] = “/usr/sbin:/sbin:” + my_env[“PATH”]
subprocess.Popen(my_command, env=my_env)

I’ve got a gut feeling that there’s a better way; does it look alright?