windows bat file question

Peter Hansen peter at engcorp.com
Tue Mar 1 12:24:06 EST 2005


Tom Willis wrote:
> I figured it out. I just took the embedded python code that was in the
> batch file distributed with it and put it in it's own module.
> 
> Really my question was how would this ever work? It seems to me to be
> a little screwy, but it would be handy to know if this was some sort
> of convention that I could take advantage of if I ever write something
> substantial that would need to run on windoze.

It looks like it might have been an untested version of something
that should have been using "python %0 %*" at that line instead
of just "python %*".

Under Windows XP (and probably NT, but not 98) the %* means
"all arguments", but doesn't appear (in testing just now on
my own machine) to include the name of the batch file itself.

On the other hand, %0 does include the name of the batch file,
but unfortunately it's actually just the part that you typed,
as in "blah" instead of "blah.bat" if you executed the file
by typing just "blah" instead of "blah.bat".

All things considered, it does look like it could never have
worked properly, but Windows is freakish enough that there
might well be some sequence of events and set of conditions
under which it might actually work as intended...

Of course, if you're on XP where you could hope that the
%* magic could work at all, you can also just modify the
contents of the environment variable PATHEXT to include .py,
rename the script to .py and strip out all that crappy
BAT stuff, and run it as intended with (almost) no
complications.

-Peter



More information about the Python-list mailing list