From 7302a9ea4ff2495c05e915df3bfea772f443438f Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Wed, 16 Aug 2017 11:07:08 +0100 Subject: [PATCH 06/16] Win32: distutils: Also look for executable.bat This patch should probably not exist, or at least be rewritten. See the comments. --- Lib/distutils/spawn.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Lib/distutils/spawn.py b/Lib/distutils/spawn.py index 5dd415a283..bef82fb1ac 100644 --- a/Lib/distutils/spawn.py +++ b/Lib/distutils/spawn.py @@ -176,17 +176,33 @@ def find_executable(executable, path=None): path = os.environ['PATH'] paths = path.split(os.pathsep) - base, ext = os.path.splitext(executable) - - if (sys.platform == 'win32') and (ext != '.exe'): - executable = executable + '.exe' + # base, ext = os.path.splitext(executable) + + if sys.platform == 'win32': + # This should probably be: + # try: + # exts = os.environ['PATHEXT'].lower().split(';')+[''] + # except: + # exts = ['.exe.', '.bat', ''] + # but IMHO: + # 1. The original `ext` should appear as the first entry. + # 2. We should be adding `exts` to `base`, not `executable` + # 3. Why even bother? We do not add '.sh' for Unix. + exts = ['.exe', '.bat', ''] + else: + exts = [''] 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 + for ext in exts: + newexe = executable + ext + if os.path.isfile(newexe): + return newexe + else: + for p in paths: + f = os.path.join(p, newexe) + if os.path.isfile(f): + # the file exists, we have a shot at spawn working + return f return None else: return executable -- 2.14.3 (Apple Git-98)