【发布时间】:2018-11-28 10:31:34
【问题描述】:
我正在编写一个脚本,如果给定应用程序已经运行,则该脚本应该关注它,否则启动该应用程序。
我正在使用subprocess 模块的run() 方法运行一些shell 命令来检查一个实例当前是否正在运行,如果没有则启动一个新实例。
如果从终端执行,该脚本工作得非常好,但是如果通过 Gnome Shell 的键盘快捷键启动,则不会执行任何操作。
我的问题是如何在不打开终端的情况下执行 shell 命令?
这是我用于 shell 命令的代码的 sn-p:
def focus_instance_of(application):
# Moves the window to the current desktop, raises it und gives it focus
print("Put " + application + " in focus...")
subprocess.run(["wmctrl", "-R", application])
【问题讨论】:
标签: python shell terminal subprocess gnome-shell