[bprobe] Use the Python subprocess module instead of os.popen3
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Subject: [bprobe] Use the Python subprocess module instead of os.popen3
- Date: Tue, 24 Mar 2009 19:18:22 -0400 (EDT)
commit ca4d3f42e97093b78bca417eb26d827a3accef3f
Author: Behdad Esfahbod <behdad behdad org>
Date: Tue Mar 24 19:17:30 2009 -0400
Use the Python subprocess module instead of os.popen3
Python 2.6 warns and suggests this change. If someone nags, I'll
make it work with both.
---
bprobe.py | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/bprobe.py b/bprobe.py
index 2bc4a82..948bc65 100755
--- a/bprobe.py
+++ b/bprobe.py
@@ -11,7 +11,7 @@ version 2 of the License, or (at your option) any later version.
See the GNU Library General Public License for more details.
"""
-import sys, getopt, os, os.path, re
+import sys, getopt, os, os.path, subprocess, re
def __log (message):
@@ -84,11 +84,13 @@ def get_metadata (probe, metadata = None, standalone = False):
#
__log ("%s: preprocessing" % probe)
__log_v (' '.join (cmd))
- (inn, out, err) = os.popen3 (cmd)
- text = out.read ()
+ PIPE = subprocess.PIPE
+ p = subprocess.Popen (cmd, stdout=PIPE, stderr=PIPE)
+ text = p.stdout.read ()
if not text:
- __fail ('%s: preprocessing failed using %s' % (probe, cpp))
-
+ __fail ('%s: preprocessing failed using %s. preprocessor error:\n%s' %
+ (probe, cpp, p.stderr.read ()))
+
# Extract metadata from the preprocessor output.
#
return __extract_metadata (metadata, text)
@@ -146,10 +148,12 @@ def compile (infile, outfile, standalone = False):
#
__log ("%s: compiling" % infile)
__log_v (cmd)
- (inn, out, err) = os.popen3 (cmd, 'r')
- errs = err.read ()
+ PIPE = subprocess.PIPE
+ p = subprocess.Popen (cmd, stdout=PIPE, stderr=PIPE, shell=True)
+ errs = p.stderr.read ()
if errs:
__fail (errs)
+ print p.stdout.read ()
if not os.path.isfile (outfile):
__fail ("%s: compiler did not produce expected output file" % outfile)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]