I'm using Popen because I need the env, like this:
Popen(
["boto-rsync", "..."],
env={"PATH":"/Library/Frameworks/Python.framework/Versions/2.7/bin/"},
)
The problem is Popen
runs the command as a new thread. Is there any way that I could pass the env
to subprocess.call
or prevent Popen
from creating a new thread?
Thanx
Subprocess call():Subprocess has a method call() which can be used to start a program. The parameter is a list of which the first argument must be the program name. The full definition is: subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False) # Run the command described by args.
Popen is nonblocking. call and check_call are blocking. You can make the Popen instance block by calling its wait or communicate method.
The recommended approach to invoking subprocesses is to use the run() function for all use cases it can handle. For more advanced use cases, the underlying Popen interface can be used directly. subprocess. call() is part of the Older high-level API (Prior to Python 3.5).
To start a new process, or in other words, a new subprocess in Python, you need to use the Popen function call. It is possible to pass two parameters in the function call. The first parameter is the program you want to start, and the second is the file argument.
You can use env
with call in the exact same way as with popen
:
subprocess.call(
["boto-rsync", "..."],
env={"PATH":"/Library/Frameworks/Python.framework/Versions/2.7/bin/"},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With