如何找到可执行文件的路径? [英] How can I find the path for an executable?

查看:63
本文介绍了如何找到可执行文件的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用二进制文件的路径设置环境.在 shell 中,我可以使用 which 来查找路径.python中有等价物吗?这是我的代码.

I need to setup environment with the path to a binary. In the shell, I can use which to find the path. Is there an equivalent in python? This is my code.

cmd = ["which","abc"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
res = p.stdout.readlines()
if len(res) == 0: return False
return True

推荐答案

distutils.spawn.find_executable().

这篇关于如何找到可执行文件的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆