【发布时间】:2011-07-10 18:18:14
【问题描述】:
我需要使用二进制文件的路径设置环境。在 shell 中,我可以使用which 来查找路径。 python中是否有等价物?
这是我的代码。
cmd = ["which","abc"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
res = p.stdout.readlines()
if len(res) == 0: return False
return True
【问题讨论】:
-
即使在 shell 本身中,
which本身也不是检测是否安装了命令的好选择。 Reference
标签: python