Created
May 18, 2015 11:00
-
-
Save Pithikos/94f3078d87d8576138c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_cmd_abspath(cmd): | |
""" Returns the absolute path to a command. | |
None is returned if no absolute path was found. | |
""" | |
if exists(cmd) or exists(cmd + '.exe'): | |
return os.path.abspath(cmd) | |
if not 'PATH' in os.environ: | |
raise Exception("Can't find command path for current platform ('%s')" % sys.platform) | |
PATH = os.environ['PATH'] | |
for path in PATH.split(os.path.pathsep): | |
for filename in os.listdir(path): | |
barename = os.path.splitext(filename)[0] | |
if filename == cmd or barename == cmd: | |
return path + os.path.sep + filename | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment