【问题标题】:Running DRI_PRIME Command By Using Python Subprocess使用 Python 子进程运行 DRI_PRIME 命令
【发布时间】:2021-12-07 14:24:03
【问题描述】:

我需要使用 Python 子进程运行 DRI_PRIME=1 glxinfo 命令,它也不应该导致 shell 注入风险。

它给出了以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'DRI_PRIME=1'

代码:

output = subprocess.check_output(["DRI_PRIME=1", "glxinfo"], shell=False).decode()
print(output)

System: Python3, OS: Linux

【问题讨论】:

    标签: python python-3.x shell subprocess


    【解决方案1】:

    使用以下代码解决问题:

    output = subprocess.check_output(["env", "DRI_PRIME=1", "glxinfo"], shell=False).decode()
    

    env手册页的简短说明:

    env - run a program in a modified environment
    

    【讨论】:

      猜你喜欢
      • 2020-07-25
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 2021-04-03
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 2015-10-29
      相关资源
      最近更新 更多