CCW said:
Thanks for this - this way made a bit more sense to me. I've now got
C:\commands with the 4 .bat files in, and C:\commands in my path. It
all seems to work
I think I've missed the point of the @ though -
it doesn't seem to make any difference..
I'm also a bit confused with the associations - since I've got python
2.6 and 3.1, surely the command I type (python26 or python31) is the
only way to force a script to be run using a specific interpreter at
runtime without having to change the .bat file every time I want to
run a script using 3.1 instead of 2.6?
The @ symbol was used in older versions of CMD and COMMAND to suppress
echoing of the command line. I think if you're using XP or later, it
doesn't matter.
As for file associations, I don't know just what you already know
about. When you type data.doc at a command line, the system looks
for the data file, then if it's found, it looks up the program
associated with that extension. On my machine, that's a particular
version of Word for Windows. Similarly, if I type digest.py and
I'm in the directory containing that file, the system looks up my
associations, and runs Python 2.6 on that file. If I wanted it to run
Python 3.1 on that file, I'd have to change the associations, temporarily.
So, first approximation, it's a way to avoid having to type PYTHON each
time I want to run a script, as long as I don't need any other arguments
on the (implied) command line. Further, the system will then look for
digest.py everywhere on the PATH, so I don't even have to be in the same
directory. And that means I can be in the data directory that digest.py
is going to work on. Effectively, it raises digest.py to feeling like
an executable, for most purposes. In fact, I put all my scripts in a
directory, along with other simple executables. I use m:\t\bin for
that purpose.
These associations (to .py and .pyw) are established by the installer
program for Python. But when you had multiple installs, you could
choose whether the second one installed overrides the first. My point
is that if you need to change them back and forth, you could use assoc
and ftype to do it.
On my system:
M:\LabOrders>assoc .py
..py=Python.File
M:\LabOrders>ftype Python.File
Python.File="C:\PROGFI~1\ACTIVE~1\python.exe" "%1" %*
M:\LabOrders>
So my .py files are associated with the 2.6.2 version of ActivePython
installation. Note the similarity of the ftype to your python26.bat file?
One more little trick is that I could just type digest instead
of digest.py, if I have added the .py and .pyw extensions to my
PATHEXT environment variable. So my PATHEXT looks like:
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PY;.PYW
Note that the association changes made by assoc and ftype are global.
They apply to all cmd.exe windows, even those already running, and they
survive a reboot. But when you set environment variables like PATHEXT,
you can choose to do it in a single window (with SET), or globally
(using control-panel).
If I found myself switching often, I'd make separate ftype entries for
each interpreter, something like
Python.File26="C:\PROGFI~1\ACTIVE~1\python.exe" "%1" %*
Python.File31="C:\PROGFI~1\.....
and just change assoc .py to point at the one I needed today.
As it is, I'm content leaving the associations pointing at 2.6, and
explicitly entering PYTHON31 in front of any script name I want to run
on that interpreter.
DaveA