【问题标题】:Check if a program is installed with Python检查程序是否安装了 Python
【发布时间】:2019-12-16 18:17:40
【问题描述】:

我的代码要求安装 UFW(简单防火墙)。该程序只能在基于 Linux 的操作系统上运行。如果发现安装了 UFW,我将如何让 Python 返回一个值?

编辑:我不想捕获输出,而是想查看文件夹(在默认安装路径中)是否存在。

【问题讨论】:

标签: python-3.x linux


【解决方案1】:

请注意,这只是链接的编辑副本

  1. How to find if directory exists in Python
  2. Check if a program exists from a python script

希望对你有帮助

import subprocess
rc = subprocess.call(['which', 'ufw'])
if rc == 0:
    print('ufw installed!')
else:
    print('ufw missing in path!')

# To check whether path exists

if os.path.exists("/usr/sbin/ufw") :
  print("path exists")
else:
  print("path doesn't exist") 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 2010-10-06
    • 1970-01-01
    • 2010-11-06
    • 2013-09-16
    • 2011-10-14
    • 1970-01-01
    • 2012-06-23
    相关资源
    最近更新 更多