diff -r 293c398cd4cf -r 171be94c2eb0 Lib/ctypes/util.py --- a/Lib/ctypes/util.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/ctypes/util.py Mon May 30 02:37:45 2011 -0700 @@ -1,5 +1,4 @@ import sys, os -import contextlib import subprocess # find_library(name) returns the pathname of a library, or None. @@ -87,26 +86,41 @@ # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump import re, tempfile, errno + def _type_finds(progname): + try: + return not subprocess.call(('type', progname), + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + except OSError: + return False + def _findLib_gcc(name): expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) fdout, ccout = tempfile.mkstemp() os.close(fdout) - cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit 10; fi;' \ - '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name + + for program in ('gcc', 'cc'): + if _type_finds(program): + cc = program + break + else: + raise OSError('gcc or cc command not found') + + cmd = (cc, '-Wl,-t', '-o', ccout, '-l', name) try: - f = os.popen(cmd) - try: - trace = f.read() - finally: - rv = f.close() + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + trace, _ = proc.communicate() + except EnvironmentError: + return None finally: try: os.unlink(ccout) except OSError as e: if e.errno != errno.ENOENT: raise - if rv == 10: - raise OSError('gcc or cc command not found') + res = re.search(expr, trace) if not res: return None @@ -118,9 +132,14 @@ def _get_soname(f): if not f: return None - cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f - with contextlib.closing(os.popen(cmd)) as f: - data = f.read() + cmd = ("/usr/ccs/bin/dump", "-Lpv", f) + try: + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL) + data, _ = proc.communicate() + except EnvironmentError: + return None res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data) if not res: return None @@ -130,13 +149,17 @@ # assuming GNU binutils / ELF if not f: return None - cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \ - "objdump -p -j .dynamic 2>/dev/null " + f - f = os.popen(cmd) - dump = f.read() - rv = f.close() - if rv == 10: + if not _type_finds('objdump'): raise OSError('objdump command not found') + + cmd = ("objdump", "-p", "-j", ".dynamic", f) + try: + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL) + dump, _ = proc.communicate() + except EnvironmentError: + return None res = re.search(r'\sSONAME\s+([^\s]+)', dump) if not res: return None @@ -160,8 +183,10 @@ def find_library(name): ename = re.escape(name) expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename) - with contextlib.closing(os.popen('/sbin/ldconfig -r 2>/dev/null')) as f: - data = f.read() + proc = subprocess.Popen(('/sbin/ldconfig', '-r'), + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL) + data, _ = proc.communicate() res = re.findall(expr, data) if not res: return _get_soname(_findLib_gcc(name)) @@ -189,7 +214,7 @@ regex = os.fsencode( '\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)) try: - with subprocess.Popen(['/sbin/ldconfig', '-p'], + with subprocess.Popen(('/sbin/ldconfig', '-p'), stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdout=subprocess.PIPE, diff -r 293c398cd4cf -r 171be94c2eb0 Lib/distutils/command/bdist_rpm.py --- a/Lib/distutils/command/bdist_rpm.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/distutils/command/bdist_rpm.py Mon May 30 02:37:45 2011 -0700 @@ -5,7 +5,7 @@ __revision__ = "$Id$" -import sys, os +import sys, os, subprocess from distutils.core import Command from distutils.debug import DEBUG from distutils.util import get_platform @@ -339,17 +339,14 @@ nvr_string = "%{name}-%{version}-%{release}" src_rpm = nvr_string + ".src.rpm" non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm" - q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % ( - src_rpm, non_src_rpm, spec_path) + q_cmd = ("rpm", "-q", "--qf", '%s %s\n' % (src_rpm, non_src_rpm), + "--specfile", spec_path) - out = os.popen(q_cmd) try: + proc = subprocess.Popen(q_cmd) binary_rpms = [] source_rpm = None - while True: - line = out.readline() - if not line: - break + for line in proc.stdout: l = line.strip().split() assert(len(l) == 2) binary_rpms.append(l[1]) @@ -357,12 +354,11 @@ if source_rpm is None: source_rpm = l[0] - status = out.close() - if status: - raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) + if proc.wait(): + raise EnvironmentError("rpm exited with non-zero exit code") - finally: - out.close() + except EnvironmentError: + raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) self.spawn(rpm_cmd) diff -r 293c398cd4cf -r 171be94c2eb0 Lib/distutils/emxccompiler.py --- a/Lib/distutils/emxccompiler.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/distutils/emxccompiler.py Mon May 30 02:37:45 2011 -0700 @@ -21,7 +21,7 @@ __revision__ = "$Id$" -import os,sys,copy +import os,sys,copy,subprocess from distutils.ccompiler import gen_preprocess_options, gen_lib_options from distutils.unixccompiler import UnixCCompiler from distutils.file_util import write_file @@ -299,11 +299,12 @@ gcc_exe = find_executable('gcc') if gcc_exe: - out = os.popen(gcc_exe + ' -dumpversion','r') try: - out_string = out.read() - finally: - out.close() + proc = subprocess.Popen((gcc_exe, '-dumpversion'), + stdout=subprocess.PIPE) + out_string, _ = proc.communicate() + except EnvironmentError: + out_string = '' result = re.search('(\d+\.\d+\.\d+)', out_string, re.ASCII) if result: gcc_version = StrictVersion(result.group(1)) diff -r 293c398cd4cf -r 171be94c2eb0 Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/idlelib/IOBinding.py Mon May 30 02:37:45 2011 -0700 @@ -1,4 +1,5 @@ import os +import subprocess import types import sys import codecs @@ -455,10 +456,11 @@ printPlatform = False if printPlatform: #we can try to print for this platform command = command % filename - pipe = os.popen(command, "r") + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) # things can get ugly on NT if there is no printer available. - output = pipe.read().strip() - status = pipe.close() + output, _ = proc.communicate() + output = output.strip() + status = proc.returncode if status: output = "Printing failed (exit status 0x%x)\n" % \ status + output diff -r 293c398cd4cf -r 171be94c2eb0 Lib/pydoc.py --- a/Lib/pydoc.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/pydoc.py Mon May 30 02:37:45 2011 -0700 @@ -53,6 +53,7 @@ # path will be displayed. import os +import subprocess import sys import builtins import imp @@ -1383,11 +1384,12 @@ def pipepager(text, cmd): """Page through text by feeding it to another program.""" - pipe = os.popen(cmd, 'w') try: - pipe.write(text) - pipe.close() - except IOError: + proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE) + proc.stdin.write(text) + proc.stdin.close() + proc.wait() + except EnvironmentError: pass # Ignore broken pipes caused by quitting the pager program. def tempfilepager(text, cmd): diff -r 293c398cd4cf -r 171be94c2eb0 Lib/test/test_posix.py --- a/Lib/test/test_posix.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/test/test_posix.py Mon May 30 02:37:45 2011 -0700 @@ -9,6 +9,7 @@ import sys import time import os +import subprocess import fcntl import pwd import shutil @@ -573,8 +574,13 @@ @unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()") def test_getgroups(self): - with os.popen('id -G') as idg: - groups = idg.read().strip() + try: + proc = subprocess.Popen(('id', '-G'), stdout=subprocess.PIPE) + groups, _ = proc.communicate() + except EnvironmentError: + groups = '' + else: + groups = groups.strip() if not groups: raise unittest.SkipTest("need working 'id -G'") diff -r 293c398cd4cf -r 171be94c2eb0 Lib/test/test_tcl.py --- a/Lib/test/test_tcl.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/test/test_tcl.py Mon May 30 02:37:45 2011 -0700 @@ -3,6 +3,7 @@ import unittest import sys import os +import subprocess from test import support # Skip this test if the _tkinter module wasn't built. @@ -145,11 +146,16 @@ with support.EnvironmentVarGuard() as env: env.unset("TCL_LIBRARY") - f = os.popen('%s -c "import tkinter; print(tkinter)"' % (unc_name,)) + args = (unc_name, '-c', "import tkinter; print(tkinter)") + try: + output = subprocess.check_output(args, stdout=subprocess.PIPE) + except subprocess.CalledProcessError: + # exit code must be zero + self.fail("Python terminated with non-zero exit code") + except EnvironmentError: + self.fail("Error trying to execute Python") - self.assertIn('tkinter', f.read()) - # exit code must be zero - self.assertEqual(f.close(), None) + self.assertIn('tkinter', output) diff -r 293c398cd4cf -r 171be94c2eb0 Lib/tkinter/test/test_tkinter/test_loadtk.py --- a/Lib/tkinter/test/test_tkinter/test_loadtk.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/tkinter/test/test_tkinter/test_loadtk.py Mon May 30 02:37:45 2011 -0700 @@ -1,5 +1,6 @@ import os import sys +import subprocess import unittest import test.support as test_support from tkinter import Tcl, TclError @@ -31,9 +32,8 @@ # doesn't actually carry through to the process level # because they don't support unsetenv # If that's the case, abort. - with os.popen('echo $DISPLAY') as pipe: - display = pipe.read().strip() - if display: + display = subprocess.check_output('echo $DISPLAY', shell=True) + if display.strip(): return tcl = Tcl() diff -r 293c398cd4cf -r 171be94c2eb0 Lib/uuid.py --- a/Lib/uuid.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/uuid.py Mon May 30 02:37:45 2011 -0700 @@ -312,25 +312,33 @@ return int((self.int >> 76) & 0xf) def _find_mac(command, args, hw_identifiers, get_index): - import os + import os, subprocess for dir in ['', '/sbin/', '/usr/sbin']: executable = os.path.join(dir, command) if not os.path.exists(executable): continue + new_env = os.environb.copy() + new_env[b'LC_ALL'] = b'C' # to get English output + cmd = executable + ' ' + args try: - # LC_ALL to get English output, 2>/dev/null to - # prevent output on stderr - cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args) - with os.popen(cmd) as pipe: - for line in pipe: - words = line.lower().split() - for i in range(len(words)): - if words[i] in hw_identifiers: - return int( - words[get_index(i)].replace(':', ''), 16) - except IOError: + # DEVNULL to prevent output on stderr + proc = subprocess.Popen(cmd, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + env=new_env) + for line in proc.stdout: + words = line.lower().split() + for i in range(len(words)): + if words[i] in hw_identifiers: + return int( + words[get_index(i)].replace(':', ''), 16) + except EnvironmentError: continue + finally: + proc.wait() + return None def _ifconfig_getnode(): @@ -370,16 +378,17 @@ pass for dir in dirs: try: - pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') - except IOError: + proc = subprocess.Popen((os.path.join(dir, 'ipconfig'), '/all'), + stdout=subprocess.PIPE) + except EnvironmentError: continue else: - for line in pipe: + for line in proc.stdout: value = line.split(':')[-1].strip().lower() if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): return int(value.replace('-', ''), 16) finally: - pipe.close() + proc.wait() def _netbios_getnode(): """Get the hardware address on Windows using NetBIOS calls. diff -r 293c398cd4cf -r 171be94c2eb0 Lib/webbrowser.py --- a/Lib/webbrowser.py Sun May 29 20:07:40 2011 +0200 +++ b/Lib/webbrowser.py Mon May 30 02:37:45 2011 -0700 @@ -570,13 +570,13 @@ %s %s end tell''' % (self.name, cmd, toWindow) # Open pipe to AppleScript through osascript command - osapipe = os.popen("osascript", "w") - if osapipe is None: + try: + osaproc = subprocess.Popen("osascript", stdin=subprocess.PIPE) + except OSError: return False # Write script to osascript's stdin - osapipe.write(script) - rc = osapipe.close() - return not rc + osaproc.stdin.write(script) + return not osaproc.wait() class MacOSXOSAScript(BaseBrowser): def __init__(self, name): @@ -593,13 +593,13 @@ end '''%(self._name, url.replace('"', '%22')) - osapipe = os.popen("osascript", "w") - if osapipe is None: + try: + osaproc = subprocess.Popen("osascript", stdin=subprocess.PIPE) + except OSError: return False - osapipe.write(script) - rc = osapipe.close() - return not rc + osaproc.stdin.write(script) + return not osaproc.wait() # Don't clear _tryorder or _browsers since OS X can use above Unix support diff -r 293c398cd4cf -r 171be94c2eb0 Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py Sun May 29 20:07:40 2011 +0200 +++ b/Mac/BuildScript/build-installer.py Mon May 30 02:37:45 2011 -0700 @@ -13,7 +13,7 @@ Usage: see USAGE variable in the script. """ import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd -import grp +import grp, subprocess INCLUDE_TIMESTAMP = 1 VERBOSE = 1 @@ -365,26 +365,23 @@ Run a command and raise RuntimeError if it fails. Output is suppressed unless the command fails. """ - fd = os.popen(commandline, 'r') - data = fd.read() - xit = fd.close() - if xit is not None: + try: + data = subprocess.check_output(commandline, shell=True) + except (subprocess.CalledProcessError, OSError) as err: + sys.stdout.write(getattr(err, output, "")) + raise RuntimeError, "command failed: %s"%(commandline,) + + if VERBOSE: sys.stdout.write(data) - raise RuntimeError, "command failed: %s"%(commandline,) - - if VERBOSE: - sys.stdout.write(data); sys.stdout.flush() + sys.stdout.flush() def captureCommand(commandline): - fd = os.popen(commandline, 'r') - data = fd.read() - xit = fd.close() - if xit is not None: - sys.stdout.write(data) + try: + return subprocess.check_output(commandline, shell=True) + except (subprocess.CalledProcessError, OSError) as err: + sys.stdout.write(getattr(err, "output", "")) raise RuntimeError, "command failed: %s"%(commandline,) - return data - def getTclTkVersion(configfile, versionline): """ search Tcl or Tk configuration file for version line @@ -552,30 +549,31 @@ retval = os.path.basename(archiveName[:-7]) if os.path.exists(retval): shutil.rmtree(retval) - fp = os.popen("tar zxf %s 2>&1"%(shellQuote(archiveName),), 'r') + args = ("tar", "zxf") elif archiveName.endswith('.tar.bz2'): retval = os.path.basename(archiveName[:-8]) if os.path.exists(retval): shutil.rmtree(retval) - fp = os.popen("tar jxf %s 2>&1"%(shellQuote(archiveName),), 'r') + args = ("tar", "jxf") elif archiveName.endswith('.tar'): retval = os.path.basename(archiveName[:-4]) if os.path.exists(retval): shutil.rmtree(retval) - fp = os.popen("tar xf %s 2>&1"%(shellQuote(archiveName),), 'r') + args = ("tar", "xf") elif archiveName.endswith('.zip'): retval = os.path.basename(archiveName[:-4]) if os.path.exists(retval): shutil.rmtree(retval) - fp = os.popen("unzip %s 2>&1"%(shellQuote(archiveName),), 'r') + args = ("unzip",) - data = fp.read() - xit = fp.close() - if xit is not None: - sys.stdout.write(data) + try: + data = subprocess.check_output(args + (archiveName,), + stderr=subprocess.STDOUT) + except (subprocess.CalledProcessError, IOError) as err: + sys.stdout.write(getattr(err, "output", "")) raise RuntimeError, "Cannot extract %s"%(archiveName,) return os.path.join(builddir, retval) diff -r 293c398cd4cf -r 171be94c2eb0 Mac/Tools/bundlebuilder.py --- a/Mac/Tools/bundlebuilder.py Sun May 29 20:07:40 2011 +0200 +++ b/Mac/Tools/bundlebuilder.py Mon May 30 02:37:45 2011 -0700 @@ -29,7 +29,7 @@ import sys -import os, errno, shutil +import os, errno, shutil, subprocess import imp, marshal import re from copy import deepcopy @@ -607,9 +607,17 @@ continue relpath = path[len(self.bundlepath):] self.message("Stripping %s" % relpath, 2) - inf, outf = os.popen4("%s -S \"%s\"" % - (STRIP_EXEC, path)) - output = outf.read().strip() + + try: + proc = Popen((STRIP_EXEC, "-S", path), + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + close_fds=True) + output, _ = proc.communicate() + except EnvironmentError: + output = "" + output = output.strip() if output: # usually not a real problem, like when we're # trying to strip a script diff -r 293c398cd4cf -r 171be94c2eb0 PC/VC6/build_ssl.py --- a/PC/VC6/build_ssl.py Sun May 29 20:07:40 2011 +0200 +++ b/PC/VC6/build_ssl.py Mon May 30 02:37:45 2011 -0700 @@ -18,7 +18,7 @@ # Developers don't need an installation of Perl anymore to build Python. A svn # checkout from our svn repository is enough. -import os, sys, re, shutil +import os, sys, re, shutil, subprocess # Find all "foo.exe" files on the PATH. def find_all_on_path(filename, extras = None): @@ -41,10 +41,9 @@ # is available. def find_working_perl(perls): for perl in perls: - fh = os.popen('"%s" -e "use Win32;"' % perl) - fh.read() - rc = fh.close() - if rc: + try: + subprocess.check_call((perl, '-e', 'use Win32;')) + except (subprocess.CalledProcessError, OSError): continue return perl print("Can not find a suitable PERL:") diff -r 293c398cd4cf -r 171be94c2eb0 PC/VS7.1/build_ssl.py --- a/PC/VS7.1/build_ssl.py Sun May 29 20:07:40 2011 +0200 +++ b/PC/VS7.1/build_ssl.py Mon May 30 02:37:45 2011 -0700 @@ -13,7 +13,7 @@ # it should configure and build SSL, then build the _ssl and _hashlib # Python extensions without intervention. -import os, sys, re +import os, sys, re, subprocess # Find all "foo.exe" files on the PATH. def find_all_on_path(filename, extras = None): @@ -36,10 +36,9 @@ # is available. def find_working_perl(perls): for perl in perls: - fh = os.popen(perl + ' -e "use Win32;"') - fh.read() - rc = fh.close() - if rc: + try: + subprocess.check_call((perl, '-e', 'use Win32;')) + except (subprocess.CalledProcessError, OSError): continue return perl print "Can not find a suitable PERL:" diff -r 293c398cd4cf -r 171be94c2eb0 PC/VS8.0/build_ssl.py --- a/PC/VS8.0/build_ssl.py Sun May 29 20:07:40 2011 +0200 +++ b/PC/VS8.0/build_ssl.py Mon May 30 02:37:45 2011 -0700 @@ -23,7 +23,7 @@ # python.exe build_ssl.py Release x64 # python.exe build_ssl.py Release Win32 -import os, sys, re, shutil +import os, sys, re, shutil, subprocess # Find all "foo.exe" files on the PATH. def find_all_on_path(filename, extras = None): @@ -46,10 +46,9 @@ # is available. def find_working_perl(perls): for perl in perls: - fh = os.popen('"%s" -e "use Win32;"' % perl) - fh.read() - rc = fh.close() - if rc: + try: + subprocess.check_call((perl, '-e', 'use Win32;')) + except (subprocess.CalledProcessError, OSError): continue return perl print("Can not find a suitable PERL:") diff -r 293c398cd4cf -r 171be94c2eb0 PCbuild/build_ssl.py --- a/PCbuild/build_ssl.py Sun May 29 20:07:40 2011 +0200 +++ b/PCbuild/build_ssl.py Mon May 30 02:37:45 2011 -0700 @@ -23,7 +23,7 @@ # python.exe build_ssl.py Release x64 # python.exe build_ssl.py Release Win32 -import os, sys, re, shutil +import os, sys, re, shutil, subprocess # Find all "foo.exe" files on the PATH. def find_all_on_path(filename, extras = None): @@ -46,10 +46,9 @@ # is available. def find_working_perl(perls): for perl in perls: - fh = os.popen('"%s" -e "use Win32;"' % perl) - fh.read() - rc = fh.close() - if rc: + try: + subprocess.check_call((perl, '-e', 'use Win32;')) + except (subprocess.CalledProcessError, OSError): continue return perl print("Can not find a suitable PERL:") diff -r 293c398cd4cf -r 171be94c2eb0 Tools/msi/msi.py --- a/Tools/msi/msi.py Sun May 29 20:07:40 2011 +0200 +++ b/Tools/msi/msi.py Mon May 30 02:37:45 2011 -0700 @@ -8,6 +8,7 @@ from distutils.spawn import find_executable from uuids import product_codes import tempfile +import subprocess # Settings can be overridden in config.py below # 0 for official python.org releases @@ -143,7 +144,6 @@ print(warning % "nm and/or dlltool were not found") return False - nm_command = '%s -Cs %s' % (nm, lib_file) dlltool_command = "%s --dllname %s --def %s --output-lib %s" % \ (dlltool, dll_file, def_file, mingw_lib) export_match = re.compile(r"^_imp__(.*) in python\d+\.dll").match @@ -152,13 +152,15 @@ f.write("LIBRARY %s\n" % dll_file) f.write("EXPORTS\n") - nm_pipe = os.popen(nm_command) - for line in nm_pipe.readlines(): + nm_command = (nm, '-Cs', lib_file) + nm_proc = subprocess.Popen(nm_command, stdout=subprocess.PIPE) + nm_output, _ = nm_proc.communicate() + for line in nm_output.splitlines(): m = export_match(line) if m: f.write(m.group(1)+"\n") f.close() - exit = nm_pipe.close() + exit = nm_proc.returncode if exit: print(warning % "nm did not run successfully") diff -r 293c398cd4cf -r 171be94c2eb0 Tools/scripts/dutree.py --- a/Tools/scripts/dutree.py Sun May 29 20:07:40 2011 +0200 +++ b/Tools/scripts/dutree.py Mon May 30 02:37:45 2011 -0700 @@ -1,12 +1,13 @@ #! /usr/bin/env python3 # Format du output in a tree shape -import os, sys, errno +import subprocess, sys, errno def main(): - p = os.popen('du ' + ' '.join(sys.argv[1:]), 'r') + proc = subprocess.Popen(['du'] + sys.argv[1:], stdout=subprocess.PIPE) + output, _ = proc.communicate() total, d = None, {} - for line in p.readlines(): + for line in output.splitlines(): i = 0 while line[i] in '0123456789': i = i+1 size = eval(line[:i]) diff -r 293c398cd4cf -r 171be94c2eb0 Tools/scripts/nm2def.py --- a/Tools/scripts/nm2def.py Sun May 29 20:07:40 2011 +0200 +++ b/Tools/scripts/nm2def.py Mon May 30 02:37:45 2011 -0700 @@ -34,19 +34,20 @@ option to produce this format (since it is the original v7 Unix format). """ -import os, sys +import subprocess, sys PYTHONLIB = 'libpython'+sys.version[:3]+'.a' PC_PYTHONLIB = 'Python'+sys.version[0]+sys.version[2]+'.dll' -NM = 'nm -p -g %s' # For Linux, use "nm -g %s" +NM = ['nm', '-p', '-g'] # For Linux, use "nm -g %s" -def symbols(lib=PYTHONLIB,types=('T','C','D')): - - lines = os.popen(NM % lib).readlines() +def symbols(lib=PYTHONLIB, types=('T','C','D')): + proc = subprocess.Popen(NM + [lib], stdout=subprocess.PIPE) + output, _ = proc.communicate() + lines = output.splitlines() lines = [s.strip() for s in lines] symbols = {} for line in lines: - if len(line) == 0 or ':' in line: + if not line or ':' in line: continue items = line.split() if len(items) != 3: