This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: find_executable fails to find .bat files on win32
Type: behavior Stage: resolved
Components: Distutils, Windows Versions: Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: eric.araujo Nosy List: abbot, alexis, christian.heimes, dstufft, eric.araujo, loewis, steve.dower, tarek, techtonik
Priority: normal Keywords: patch

Created on 2008-02-28 13:52 by abbot, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
spawn.patch abbot, 2008-03-02 15:29
spawn.patch.txt techtonik, 2008-09-03 15:41
Messages (18)
msg63092 - (view) Author: Lev Shamardin (abbot) Date: 2008-02-28 13:52
distutils.spawn.find_executable appends '.exe' suffix on win32 and os2
platforms. This is incorrect behavior, since it prevents finding .bat,
.cmd and other similar files. Ether all extensions from the %PATHEXT%
must be checked or filenames both with appended suffix and without
appending suffix must be checked.
msg63164 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-03-01 16:06
Can you provide a patch which uses PATHEXT and falls back to .com, .exe
and .bat?
msg63180 - (view) Author: Lev Shamardin (abbot) Date: 2008-03-02 15:29
Here is my vision of this patch. I don't think that it is necessary to
fall back to 'com/exe/bat' if PATHEXT is not set, since it must be set
on any correctly configured Win32 platform.
msg63213 - (view) Author: Lev Shamardin (abbot) Date: 2008-03-03 15:12
I can't see this issue on the 'open issues' list nor in the search
results. Is something wrong?
msg63216 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-03-03 16:57
By default issues are sorted by priority. I've given the bug the
priority "normal". Have a look on page 3 or 4.
msg72388 - (view) Author: anatoly techtonik (techtonik) Date: 2008-09-03 15:40
I've run into the same problem.

Attached patch (updated with Lev code) is almost the same except that it
doesn't attempt to return executable files without executable extension.

It also accounts that os2 executables can have arbitrary extensions
according to Perl manual.
msg116980 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-09-20 21:33
I think distutils changes should be aimed at several versions, please correct them if I'm wrong.
msg117003 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-20 23:31
distutils bugs follow standard Python rules: They are fixed in stable and development branches, now 2.7, 3.1 and py3k.  If there is a security hazard, the fix would go into 2.6 and possibly 2.5 too.

distutils2 has to work with 2.4-2.7 and (soon) 3.1-3.2, so Tarek told me to set all available versions for those bugs (2.5-py3k), even if I think “3rd party” is more appropriate and useful (since a distutils2 bug would not for example block a CPython 3.2 release).

When a bug applies to distutils and distutils2, I prefer to set only versions relevant for distutils.  distutils2 has only one branch which is tested with all supported Python version, and I actually consider distutils2 a version of distutils: It makes more sense to me to think “this bug exists in CPython 3.1, 3.2 and distutils2”.
msg117004 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-20 23:34
Could someone provide use cases for this change?  What programs which were not .exe did you need to run though distutils?
msg117033 - (view) Author: Lev Shamardin (abbot) Date: 2010-09-21 06:56
My use case was compiling PyQt4 resources and Qt Designer .ui files from setup script using pyrcc4 and pyuic4 commands. On windows pyrcc4 is actually a pyrcc4.bat file (at least it was at the time of the original bug submission - haven't checked current status), and find_exe could not find it.
msg117037 - (view) Author: anatoly techtonik (techtonik) Date: 2010-09-21 08:56
I believe I had problems with SCons and other .py scripts that are installed as executable .bat files on Windows.
msg117038 - (view) Author: anatoly techtonik (techtonik) Date: 2010-09-21 08:56
Another use case for .bat files is adddin extra params for executable files.
msg117043 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-21 10:32
Thanks for the use cases.  I agree this is a bug, not a feature, so unless Tarek disagrees I will commit the last patch.

I'm not sure this requires tests.
msg128504 - (view) Author: Alexis Metaireau (alexis) * (Python triager) Date: 2011-02-13 15:06
Have the patch been applied ? (the state is still open since last message)
msg128512 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-02-13 15:44
Not yet.
msg131528 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-20 19:12
Martin, could you please review patch file11359?
msg131532 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-03-20 20:04
I think the patch is incorrect. Parsing PATHEXT means that it will believe that all extensions listed on PATHEXT are executable. However, os.spawnv is not able to run them all, but only a subset. IIUC, spawnv supports (from spawnve.c)

static _TSCHAR *ext_strings[] = { _T(".cmd"), _T(".bat"), _T(".exe"), _T(".com") };

PATHEXT typically includes also .js and other extensions which cannot be run through spawnv.
msg386395 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-03 18:26
Distutils is now deprecated (see PEP 632) and all tagged issues are being closed. From now until removal, only release blocking issues will be considered for distutils.

If this issue does not relate to distutils, please remove the component and reopen it. If you believe it still requires a fix, most likely the issue should be re-reported at
Date User Action Args
2022-04-11 14:56:31adminsetgithub: 46453
2021-02-03 18:26:37steve.dowersetstatus: open -> closed

nosy: + steve.dower
messages: + msg386395

resolution: accepted -> out of date
stage: patch review -> resolved
2014-08-10 19:54:28BreamoreBoysetnosy: + dstufft

components: - Distutils2
versions: + Python 3.4, Python 3.5, - 3rd party, Python 3.1, Python 3.2, Python 3.3
2014-02-03 19:17:10BreamoreBoysetnosy: - BreamoreBoy
2011-03-20 20:04:18loewissetnosy: loewis, techtonik, christian.heimes, tarek, abbot, eric.araujo, alexis, BreamoreBoy
messages: + msg131532
2011-03-20 19:12:17eric.araujosetnosy: + loewis

messages: + msg131528
versions: + Python 3.3
2011-02-13 15:44:42eric.araujosetnosy: techtonik, christian.heimes, tarek, abbot, eric.araujo, alexis, BreamoreBoy
messages: + msg128512
2011-02-13 15:06:19alexissetnosy: + alexis
messages: + msg128504
2010-09-29 23:46:55eric.araujosetversions: + 3rd party
2010-09-21 10:32:33eric.araujosetassignee: tarek -> eric.araujo
resolution: accepted
messages: + msg117043
stage: patch review
2010-09-21 08:56:53techtoniksetmessages: + msg117038
2010-09-21 08:56:09techtoniksetmessages: + msg117037
2010-09-21 06:56:41abbotsetmessages: + msg117033
2010-09-20 23:34:18eric.araujosetmessages: + msg117004
2010-09-20 23:31:33eric.araujosetnosy: techtonik, christian.heimes, tarek, abbot, eric.araujo, BreamoreBoy
messages: + msg117003
components: + Distutils2
versions: - Python 2.6, Python 2.5
2010-09-20 21:33:31BreamoreBoysetnosy: + BreamoreBoy, eric.araujo

messages: + msg116980
versions: + Python 2.6, Python 2.5, Python 3.1, Python 3.2
2010-08-03 18:56:42terry.reedysetversions: - Python 2.6, Python 2.5, Python 3.0
2009-02-28 17:45:15akitadasetnosy: + tarek
components: + Windows
assignee: tarek
2008-09-03 15:41:20techtoniksetfiles: + spawn.patch.txt
2008-09-03 15:41:10techtoniksetfiles: - spawn.patch.txt
2008-09-03 15:40:08techtoniksetfiles: + spawn.patch.txt
nosy: + techtonik
messages: + msg72388
versions: + Python 2.6, Python 3.0, Python 2.7
2008-03-03 16:57:38christian.heimessetmessages: + msg63216
2008-03-03 15:12:56abbotsetmessages: + msg63213
2008-03-02 15:29:32abbotsetfiles: + spawn.patch
keywords: + patch
messages: + msg63180
2008-03-01 16:06:17christian.heimessetpriority: normal
nosy: + christian.heimes
messages: + msg63164
2008-02-28 13:52:12abbotcreate