[Distutils] How to handle launcher script importability?

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Aug 14 17:49:49 CEST 2013


On 14 August 2013 14:48, Paul Moore <p.f.moore at gmail.com> wrote:
>
> But I do see your point regarding things like subprocess. It's a shame, but
> anything other than exes do seem to be second class citizens on Windows.
> BTW, you mention bat files - it bugs me endlessly that bat files seem to
> have a more privileged status than "other" script formats whether that's .py
> or .ps1 or whatever. I've never managed to 100% convince myself that they
> are special in a way that you can't replicate with suitable settings
> (PATHEXT, etc, etc). I think it's that .bat is hard-coded in the OS search
> algorithm or something, though.

I think it is hard-coded into CreateProcess (at least on some versions
of Windows). It certainly isn't a documented feature, but as
demonstrated in my previous post it does work on XP.

> The docs are not easy to locate on the
> various aspects of matter.

I just tried to find documentation but all I found was this (with
dead-links to MS):
http://blog.kalmbachnet.de/?postid=34

> (If bat files didn't have their horrible nesting
> and ctrl-C handling behaviours, they'd be a viable solution...)

You were right to cry about these previously.

To give an example of where these subprocess issues might matter.
sphinx auto-generates Makefiles that call 'sphinx-build' with no
extension. The sphinx-build command has a setuptools .exe wrapper so
that it will be picked up. I wouldn't confidently assume that for all
combinations of Windows version and 'make' implementation that 'make'
would know how to find sphinx-build for anything other than an .exe.

A quick experiment shows that my own make handles shebangs if present
and then falls back to just calling CreateProcess which handles .exe
files and (via the undocumented hack above) .bat files . It does not
respect PATHEXT and the error when the extension is provided but no
shebang is given clearly shows it using the same sys-call as used by
Python's subprocess module:

Q:\tmp>show main
'show' is not recognized as an internal or external command,
operable program or batch file.

Q:\tmp>type Makefile
all:
        mycmd.py

Q:\tmp>type mycmd.py

print 'hello'

Q:\tmp>make
mycmd.py
process_begin: CreateProcess(Q:\tmp\mycmd.py, mycmd.py, ...) failed.
make (e=193): Error 193
make: *** [all] Error 193

Q:\tmp>mycmd.py
hello


Oscar


More information about the Distutils-SIG mailing list