我目前正试图弄清楚如何在Linux上通过Python访问某种“linux api”。 我的问题是,我一直想在Windows上以autoit的方式做事情,所以我不仅要掌握新的语言,还要掌握操作系统。
基本上我的代码将是这样的:
while (1) if winexists("windowname") = 1 then kill(pid) endif wend
通过Windows API或直接通过autoit来做到这一点是我可以做的,但我不知道如何处理这个在Linux中。 而且我在google上找不到太多的相关search结果。 我不想找人为我编码,只需要指出正确的方向。
您可以使用subprocess
wmctrl
模块使用外部程序(如wmctrl
)输出:
import subprocess def winexists(target): for line in subprocess.check_output(['wmctrl', '-l']).splitlines(): window_name = line.split(None, 3)[-1].decode() if window_name == target: return True return False
请参阅superuser.com中的相关问题 – 获取Linux中打开的窗口的列表 。