summaryrefslogtreecommitdiff
path: root/coverage/backward.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-07-08 14:05:36 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-07-08 14:05:36 -0400
commit22b8005db24279b04deea3ac20dd632f8b600763 (patch)
tree78ab6c5e98af1c6d81df0676dcdb2952d0915eee /coverage/backward.py
parentd3edb493b6cafd26e7881d5dc86b00bda471dc94 (diff)
downloadpython-coveragepy-git-22b8005db24279b04deea3ac20dd632f8b600763.tar.gz
Py3k: unify subprocess and popen4.
Diffstat (limited to 'coverage/backward.py')
-rw-r--r--coverage/backward.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 506649d2..91f07bf6 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -4,6 +4,7 @@
# (Redefining built-in blah)
# The whole point of this file is to redefine built-ins, so shut up about it.
+import os
# Python 2.3 doesn't have `set`
try:
@@ -22,3 +23,29 @@ except NameError:
lst = list(iterable)
lst.sort()
return lst
+
+# Py2k and 3k don't agree on how to run commands in a subprocess.
+try:
+ import subprocess
+except ImportError:
+ def run_command(cmd):
+ """Run a command in a subprocess.
+
+ Returns the exit code and the combined stdout and stderr.
+
+ """
+ _, stdouterr = os.popen4(cmd)
+ return 0, stdouterr.read()
+else:
+ def run_command(cmd):
+ """Run a command in a subprocess.
+
+ Returns the exit code and the combined stdout and stderr.
+
+ """
+ proc = subprocess.Popen(cmd, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT
+ )
+ retcode = proc.wait()
+ return retcode, proc.stdout.read()