Windows+Python Integration Like Unix shell

1 min read · Posted on: Aug 12, 2005 · Print this page

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!

Arun Ravindran profile pic

Arun Ravindran

Arun is the author of "Django Design Patterns and Best Practices". Works as a Product Manager at Google. Avid open source enthusiast. Keen on Python. Loves to help people learn technology. Find out more about Arun on the about page.

Don't miss any future posts!

Comments →

Next: ▶   Missed by Several Degrees

Prev: ◀   A Water Bourne Weekend

Up: ▲   Blog

Featured Posts

Frequent Tags

banner ad for Django book


powered by Disqus