Skip to content

Instantly share code, notes, and snippets.

@gvx
Created June 28, 2009 13:04
Show Gist options
  • Save gvx/137261 to your computer and use it in GitHub Desktop.
Save gvx/137261 to your computer and use it in GitHub Desktop.
A Python script to enable #! for Windows
#By Robin Wellner (gvx)
#I hereby waive copyright and related or neighboring rights to this work
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/>
import sys
import subprocess
f = open (sys.argv[1], "r")
r = f.readline()[:-1]
f.close()
special = {
#for example:
#'python2.6': "C:\\Python26\\python.exe",
#'python3.1': "C:\\Python31\\python.exe",
}
if r.startswith("#!"):
r = r[2:].strip()
if r in special:
line = special[r]
else:
line = r
subprocess.call([line] + sys.argv[1:])
else:
sys.exit("Could not execute: file does not start with shebang.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment