In Windows you can change file associations from the command line using the assoc
and ftype
commands (You can currently download a Windows Command Reference PDF file from here).
You can see what file type is currently associated with .py files using the assoc
command:
> assoc .py
.py=Python.File
With that information you can then check to see what program is currently associated with the Python.File
file type using the ftype
command:
> ftype Python.File
Python.File="C:\Python2.6\python.exe" "%1" %*
You can also use ftype
to change the associated program:
> ftype Python.File="C:\Python2.7\python.exe" "%1" %*
Python.File="C:\Python2.7\python.exe" "%1" %*
Associations set this way are persistent because they're stored in the Windows Registry. That means you will need to set or restore it to what you want before terminating the cmd.exe
session. I'd suggest using one or more batch files for this purpose.
cmd.exe
itself accepts a /k
parameter, which you could use to have it execute a batch file at start up that sets up the file association you want initially. You could then also provide a custom quit.bat
that would restore it before exiting the cmd
session.