How to close a cmd window using python 2.7

前端 未结 5 906
南方客
南方客 2021-01-15 06:03

The title pretty much says it, although it does not need to be specific to a cmd, just closing an application in general. I have seen

os.system(taskkill bla         


        
5条回答
  •  终归单人心
    2021-01-15 06:51

    For anyone who's stuck with Python 2.7 and unable to download pywin32 thanks to red tape in your organization. If you're on Windows XP and above you can use taskkill to kill the process by window title name like below for a dos command prompt that was started in elevated mode with title MyTitle

    os.system('taskkill /fi "WindowTitle eq Administrator: MyTitle"')
    

提交回复
热议问题