Skip to content

Instantly share code, notes, and snippets.

@winny-
Last active August 29, 2015 14:01
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 winny-/8fb7f90584f7f3aca30e to your computer and use it in GitHub Desktop.
Save winny-/8fb7f90584f7f3aca30e to your computer and use it in GitHub Desktop.
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