Kaydet (Commit) 19e5b3f9 authored tarafından Marc-André Lemburg's avatar Marc-André Lemburg

Use a new global DEV_NULL instead of hard-coding /dev/null into the system

command helper functions.

See #6479 for some motivation.
üst 9d11fefe
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
# #
# <see CVS and SVN checkin messages for history> # <see CVS and SVN checkin messages for history>
# #
# 1.0.7 - added DEV_NULL
# 1.0.6 - added linux_distribution() # 1.0.6 - added linux_distribution()
# 1.0.5 - fixed Java support to allow running the module on Jython # 1.0.5 - fixed Java support to allow running the module on Jython
# 1.0.4 - added IronPython support # 1.0.4 - added IronPython support
...@@ -91,7 +92,7 @@ ...@@ -91,7 +92,7 @@
__copyright__ = """ __copyright__ = """
Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
Copyright (c) 2000-2008, eGenix.com Software GmbH; mailto:info@egenix.com Copyright (c) 2000-2009, eGenix.com Software GmbH; mailto:info@egenix.com
Permission to use, copy, modify, and distribute this software and its Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee or royalty is hereby granted, documentation for any purpose and without fee or royalty is hereby granted,
...@@ -110,10 +111,25 @@ __copyright__ = """ ...@@ -110,10 +111,25 @@ __copyright__ = """
""" """
__version__ = '1.0.6' __version__ = '1.0.7'
import sys,string,os,re import sys,string,os,re
### 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
# Python versions
if sys.platform in ('dos','win32','win16','os2'):
# Use the old CP/M NUL as device name
DEV_NULL = 'NUL'
else:
# Standard Unix uses /dev/null
DEV_NULL = '/dev/null'
### Platform specific APIs ### Platform specific APIs
_libc_search = re.compile(r'(__libc_init)' _libc_search = re.compile(r'(__libc_init)'
...@@ -926,7 +942,7 @@ def _syscmd_uname(option,default=''): ...@@ -926,7 +942,7 @@ def _syscmd_uname(option,default=''):
# XXX Others too ? # XXX Others too ?
return default return default
try: try:
f = os.popen('uname %s 2> /dev/null' % option) f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
except (AttributeError,os.error): except (AttributeError,os.error):
return default return default
output = string.strip(f.read()) output = string.strip(f.read())
...@@ -951,7 +967,7 @@ def _syscmd_file(target,default=''): ...@@ -951,7 +967,7 @@ def _syscmd_file(target,default=''):
return default return default
target = _follow_symlinks(target) target = _follow_symlinks(target)
try: try:
f = os.popen('file "%s" 2> /dev/null' % target) f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
except (AttributeError,os.error): except (AttributeError,os.error):
return default return default
output = string.strip(f.read()) output = string.strip(f.read())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment