# HG changeset patch # User shamardin@gmail.com # Date 1204470842 -3600 # Node ID ea78e3f26dbb453279fd4246bd3186ea6f7927f8 # Parent b4f537506f10a315829351f011b843aca1628da1 Patch to handle extensions from %PATHEXT% on Win32. diff -r b4f537506f10 -r ea78e3f26dbb spawn.py --- a/spawn.py Sun Mar 02 16:13:16 2008 +0100 +++ b/spawn.py Sun Mar 02 16:14:02 2008 +0100 @@ -180,22 +180,32 @@ """Try to find 'executable' in the directories listed in 'path' (a string listing directories separated by 'os.pathsep'; defaults to os.environ['PATH']). Returns the complete filename or None if not - found. + found. On Win32 tries to append all extensions from the %PATHEXT% + during search if executable has an extension not found in + %PATHEXT% or has no extension at all. On OS/2 appends .exe + extension to the file before search if it is missing. """ if path is None: path = os.environ['PATH'] paths = string.split(path, os.pathsep) + exts = [''] (base, ext) = os.path.splitext(executable) - if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'): + if sys.platform == 'win32': + pathexts = os.environ['PATHEXT'].lower().split(os.path.pathsep) + if ext.lower() not in pathexts: + exts.extend(pathexts) + elif os.name == 'os2' and ext.lower() != '.exe': executable = executable + '.exe' - if not os.path.isfile(executable): - for p in paths: - f = os.path.join(p, executable) - if os.path.isfile(f): - # the file exists, we have a shot at spawn working - return f - return None - else: - return executable + for ext in exts: + exename = executable + ext + if not os.path.isfile(exename): + for p in paths: + f = os.path.join(p, exename) + if os.path.isfile(f): + # the file exists, we have a shot at spawn working + return f + else: + return executable + return None # find_executable()