diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -107,17 +107,17 @@ __copyright__ = """ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE ! """ __version__ = '1.0.7' import collections -import sys, os, re +import sys, os, re, subprocess ### Globals & Constants # Determine the platform's /dev/null device try: DEV_NULL = os.devnull except AttributeError: # os.devnull was added in Python 2.4, so emulate it for earlier @@ -917,23 +917,25 @@ def _syscmd_file(target,default=''): The function uses the -b option of the file command to have it omit the filename in its output. Follow the symlinks. It returns default in case the command should fail. """ if sys.platform in ('dos','win32','win16','os2'): # XXX Others too ? return default - target = _follow_symlinks(target).replace('"', '\\"') + target = _follow_symlinks(target) try: - f = os.popen('file -b "%s" 2> %s' % (target, DEV_NULL)) + with open(DEV_NULL) as dev_null: + proc = subprocess.Popen(['file', '-b', '--', target], + stdout=subprocess.PIPE, stderr=dev_null) except (AttributeError,os.error): return default - output = f.read().strip() - rc = f.close() + output = proc.stdout.read() + rc = proc.wait() if not output or rc: return default else: return output ### Information about the used architecture # Default values for architecture; non-empty strings override the