windows bat file question

Duncan Booth duncan.booth at invalid.invalid
Thu Mar 3 08:38:02 EST 2005


Peter Hansen wrote:

>> This should make it work:
>>   python %0.bat %*
> 
> Only, among other issues, if you type the full path to the
> batch file, or if it's in the current directory.  This
> approach fails if you put the batch file in a directory
> somewhere along your path.

The simplest fix, assuming we aren't talking Win9x is probably:

 python "%~f0" %*

> There are only a couple of useful ways to do this sort of
> thing under Windows operating systems, and the easiest by
> far is to abandon any support for Windows 98 and just use
> the PATHEXT support in Windows NT/XP and friends.

And if you can't be bothered with PATHEXT then just make sure to always 
type the .py in as part of the command line: 

   C:\>myscript.py

will run a Python script without any messing. If the script is in the 
current directory then you can use tab completion to avoid typing the whole 
name anyway.




More information about the Python-list mailing list