Issue
I need to run DRI_PRIME=1 glxinfo
command by using Python subprocess also it should not cause shell injection risk.
It gives the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'DRI_PRIME=1'
Code:
output = subprocess.check_output(["DRI_PRIME=1", "glxinfo"], shell=False).decode()
print(output)
System: Python3, OS: Linux
Solution
The problem is solved by using the following code:
output = subprocess.check_output(["env", "DRI_PRIME=1", "glxinfo"], shell=False).decode()
A short explanation from manual page of env
:
env - run a program in a modified environment
Answered By - pythonlearner9001
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.