Skip to content

Instantly share code, notes, and snippets.

@zabbarob
Created September 15, 2013 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zabbarob/6574782 to your computer and use it in GitHub Desktop.
Save zabbarob/6574782 to your computer and use it in GitHub Desktop.
check if an executable exist and where it is stored From http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment