简体   繁体   English

用python脚本终止正在运行的应用程序

[英]To terminate the running application in python script

I am writing a simple python script to run and close one flatpak application. 我正在编写一个简单的python脚本来运行和关闭一个flatpak应用程序。 I am triggering gedit application using flatpak command but having a hard time to figure out how to quit the application from script itself. 我正在使用flatpak命令触发gedit应用程序,但很难弄清楚如何从脚本本身退出该应用程序。 Since once the application launches, python scripts waits for the application to terminate and then to exit. 由于应用程序启动后,Python脚本会等待应用程序终止然后退出。

Code: 码:

import os
import sys

def main():
    os.system("flatpak run org.gnome.gedit/x86_64/stable")
    sys.exit()

if __name__ == '__main__':
    main() 

In above code I tried sys.exit() , but it doesn't work as it waits for the application to terminate. 在上面的代码中,我尝试了sys.exit() ,但是它在等待应用程序终止时不起作用。

you can try this 你可以试试这个

import subprocess
p = subprocess.Popen("flatpak run org.gnome.gedit/x86_64/stable")
p.terminate()

Here you can find more information about this 在这里您可以找到有关此的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM