Skip to content

Instantly share code, notes, and snippets.

@avamsi
Created October 14, 2016 16:50
Show Gist options
  • Save avamsi/ed4473b83d6a6a1a051e5e841b5f48e3 to your computer and use it in GitHub Desktop.
Save avamsi/ed4473b83d6a6a1a051e5e841b5f48e3 to your computer and use it in GitHub Desktop.
@echo off & python -x %~f0 %* & goto :EOF
import os.path
import sys
import subprocess
PATH_PREFIXES = [r'C:\Python27', r'C:\Python27\Scripts',
r'C:\Python27\Library\bin', '']
EXTENSIONS = ['.exe', '.cmd', '.bat']
def get_path(path):
for path_prefix in PATH_PREFIXES:
for extension in EXTENSIONS:
runnable = os.path.join(path_prefix, path) + extension
if os.path.exists(runnable):
return runnable
return path
args = sys.argv[1:]
args[0] = get_path(sys.argv[1])
subprocess.run(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment