Windows+Python Integration Like Unix shell

2005 August 12
by Arun Bhai

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 foo.py

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 %*
set PATHEXT=.py;%PATHEXT%

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:

REGEDIT4
[HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
"AutoRun"="startme.bat"

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!

Distantly Related posts:

  1. Making Python Scripts Show Windows-friendly Errors/Stacktrace
  2. Work Faster in Windows With Launchy and a few Python Scripts
  3. Is Python Intellisense Possible in Emacs?
  4. Decoding Google’s First Tweet in Python
  5. 5 Indispensable Tips for Emacs on Windows
No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS

Additional comments powered by BackType