def which(cmd):
path = os.environ.get("PATH", os.defpath)
if not path:
return None
path = [get_tools_path()] + path.split(os.pathsep) + ["."]
if sys.platform == "win32":
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
files = [cmd + ext for ext in pathext]
else:
files = [cmd]
seen = set()
for dir in path:
normdir = os.path.normcase(dir)
if normdir not in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
if os.path.exists(name):
return name
return None
评论列表
文章目录