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!

Share on: Twitter, Hacker News, Reddit, Facebook, Google+

Posted on: Fri, Aug 12, 2005

Next: ▶  Missed by Several Degrees

Prev: ◀  A Water Bourne Weekend

Up: ▲  Blog

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.

Frequent Tags

python (36) django (18) movies (11) productivity (11) tutorial (10) gaming (8) humour (8) creativity (7) featured (7) screencast (7) python3 (6) review (6) programming (5) wordpress (5)

Don't miss any future posts!


comments powered by Disqus