Last active
August 29, 2015 14:01
-
-
Save winny-/8fb7f90584f7f3aca30e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import sys | |
def which(command): | |
paths = os.getenv('PATH', '').split(os.pathsep) | |
for path in paths: | |
possible_command = os.path.join(path, command) | |
is_valid_command = os.path.isfile(possible_command) and \ | |
os.access(possible_command, os.X_OK) | |
if is_valid_command: | |
return possible_command | |
if __name__ == '__main__': | |
success = True | |
for command in sys.argv[1:]: | |
found = which(command) | |
if found: | |
print(found) | |
else: | |
success = False | |
sys.exit(not success) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment