[英]kill a task with name containing whitespace using python os.system
From a python script, I am trying to terminate a task.从 python 脚本,我试图终止一个任务。 The task name contains whitespace.任务名称包含空格。
Like "My Program.exe" for instance.例如“My Program.exe”。
I use the following line but it complains about invalid argument because the name contains a whitespace.我使用以下行,但它抱怨无效参数,因为名称包含空格。
os.system("TASKKILL /F /IM My Program.exe")
I can't find how to escape the whitespace.我找不到如何逃避空白。
I tried我试过
os.system("TASKKILL /F /IM "My Program.exe"")
os.system("TASKKILL /F /IM \"My Program.exe\"")
os.system("TASKKILL /F /IM 'My Program.exe'")
os.system("TASKKILL /F /IM \'My Program.exe\'")
But still does not work.但仍然不起作用。
This worked for me:这对我有用:
os.system("TASKKILL /F /IM \"My Program.exe\"")
Check if your application is really named 'My Program.exe' on task manager.检查您的应用程序是否真的在任务管理器上命名为“My Program.exe”。 Also, check if you have privileges to be killing that process.另外,请检查您是否有权杀死该进程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.