Windows+Python Integration Like Unix shell

Remember how in UNIX how easy it was to run python scripts? Just type name of the script. No need to even type the extension .py

I got soon fed up with typing

C: > python

in windows. Digging up some Microsoft documentation, I soon found a way to simply type

C: > foo

and make it work. How? read on…

All you need is to create a batchfile, say ‘startme.bat’ with the two lines

ASSOC .py=PythonScript
FTYPE PythonScript=python.exe %1 %*

If you want this to be the default behaviour everywhere, put this in ‘autoexec.bat’. But wait, we have a better way to do this. You can make ‘startme.bat’ work like ‘.bashrc’ in UNIX by registry hack. Create a REG file, say ‘cmd-changer.reg’ with the contents:

[HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]

Now opening this file will merge it to the registry. Now ‘startme.bat’ will be run every time you open the command prompt say by typing ‘cmd.exe’ in the Run command box. Hope this helps!

Hi! Welcome to ArunRocks, an odd collection of writeups on programming, travel, gadgets and practically anything under the sun. This state of affairs could be blamed on the ecelectic interests of your host, Arun Ravindran. He loves programming in several languages especially Python. He is currently a developer member of the Django Software Foundation. Read more...