Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Python 2.6 subprocess module in Python 2.5

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?

like image 391
xyz Avatar asked Feb 16 '09 06:02

xyz


People also ask

How do I use OS Popen in Python?

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.

What is the difference between subprocess run and subprocess Popen?

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.

Is subprocess part of Python standard library?

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.


1 Answers

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.

like image 72
Kamil Kisiel Avatar answered Oct 14 '22 22:10

Kamil Kisiel