[Distutils] small improvement of the script functionality under win32

Phillip J. Eby pje at telecommunity.com
Wed Mar 30 18:41:23 CEST 2005


At 09:51 AM 3/30/05 +0200, M.-A. Lemburg wrote:
>
> > #!C:\Python24\python.exe -x "%~f0"  foo bar & exit /b
>
>Sounds like a good idea. The only thing I don't understand is
>why you'd want to use ".cmd" instead of the more common ".bat".

This doesn't work on Windows 98 at *all*:

* 98 doesn't support .cmd files
* 98 doesn't have a /b option for 'exit'
* 98 doesn't pay attention to the '&'
* 98 doesn't have a way to get the filename being executed (as opposed to 
argument 0)

The closest I was able to get this to working was to use a .bat, at which 
point the Python part runs, but then Windows tries to execute the Python 
script as a batch file.  Maybe somebody smarter than me can come up with a 
way to fix that.  The following is the closest I got to a working .bat:

@c:\python23\python.exe -x "%0"
rem = """
@goto exit
"""

print "hello world"    # this is the script

"""
:exit
@rem"""


This still has some important flaws; first the %0 is fragile, because it 
has to be the actual filename, so it's not really going to work unless 
Python searches PATH and PATHEXT.  Second, it outputs the 'rem = """' line, 
and I don't know any way around that.  Third, you can't have a docstring or 
'from __future__'.

Anyway, I guess my point is that the patch should *not* be accepted unless 
it actually checks whether the Windows version is high enough to support 
these features.




More information about the Distutils-SIG mailing list