Suffixes = [ ".exe" ] def findExecutable(name, alwaysAddSuffix=False): """Find an executable file matching given name. Directories on the PATH environment variable are checked first, followed by a list of "standard" directories.""" import os, os.path execNames = _getExecNames(name, alwaysAddSuffix) path = os.getenv("PATH", os.defpath) pathList = path.split(os.pathsep) for p in pathList: for e in execNames: filename = os.path.join(p, e) if os.access(filename, os.X_OK): return filename return _findInstalledApp(execNames) def _getExecNames(name, alwaysAddSuffix): import os.path if not alwaysAddSuffix: root, suffix = os.path.split(name) if not suffix: alwaysAddSuffix = True if alwaysAddSuffix: execNames = [ name + suffix for suffix in Suffixes ] execNames.insert(0, name) else: execNames = [ name ] return execNames import sys if sys.platform == "win32": import os, os.path InstallDirs = [] pf = os.path.join(os.path.splitdrive(sys.executable)[0], os.sep, "Program Files") try: dirList = os.listdir(pf) except OSError: pass else: for dname in dirList: dir = os.path.join(instDir, dname) if os.path.isdir(dir): InstallDirs.append(dir) else: InstallDirs = [ "/usr/local/bin", "/usr/bin" "/bin", ] def _findInstalledApp(execNames): import os, os.path for dir in InstallDirs: for e in execNames: filename = os.path.join(dir, e) if os.access(filename, os.X_OK): return filename return None