What’s the difference between subprocess Popen and call (how can I use them)?

I want to call an external program from Python. I have used both Popen() and call() to do that. What’s the difference between the two? My specific goal is to run the following command from Python. I am not sure how redirects work. ./my_script.sh > output I read the documentation and it says that call() … Read more

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? 2 Answers 2

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? 8 Answers 8