如何从python检查DISPLAY =:0是否存在?

问题描述 投票:1回答:1

命令:

ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u

输出:

DISPLAY=:0

如何从python检查DISPLAY=:0是否存在?

虽然DISPLAY=:0存在,但import os; print(os.environ['DISPLAY'])不存在。>>

由于某种原因,这会输出空字符串:

import subprocess
subprocess.getoutput('ps e | grep -Po " DISPLAY=[\\.0-9A-Za-z:]* " | sort -u')

输出:

''

命令:ps e | grep -Po“ DISPLAY = [\。0-9A-Za-z:] *” | sort -u输出:DISPLAY =:0如何从python检查DISPLAY =:0?当DISPLAY =:0存在时,导入os; print(os.environ ['DISPLAY'])不能。 ...

python bash xorg xserver
1个回答
0
投票

为我工作:

© www.soinside.com 2019 - 2024. All rights reserved.