I would like to use Python 2.6's version of subprocess, because it allows the Popen.terminate() function, but I'm stuck with Python 2.5. Is there some reasonably clean way to use the newer version of the module in my 2.5 code? Some sort of from __future__ import subprocess_module
?
Python method popen() opens a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as in open() function.
The main difference is that subprocess. run() executes a command and waits for it to finish, while with subprocess. Popen you can continue doing your stuff while the process finishes and then just repeatedly call Popen. communicate() yourself to pass and receive data to your process.
The subprocess library allows us to execute and manage subprocesses directly from Python. That involves working with the standard input stdin , standard output stdout , and return codes. We don't have to install it with PIP, since it's part of the Python standard library.
I know this question has already been answered, but for what it's worth, I've used the subprocess.py
that ships with Python 2.6 in Python 2.3 and it's worked fine. If you read the comments at the top of the file it says:
# This module should remain compatible with Python 2.2, see PEP 291.
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