Python-无法终止进程

Python-无法终止进程,python,subprocess,popen,kill,terminate,Python,Subprocess,Popen,Kill,Terminate,我正在使用Python3.5和Windows7。我正在尝试打开一个exe文件,然后终止它。我成功地打开了它,但无法关闭它。以下是我的代码的缩写版本: from subprocess import Popen open = Popen(["filename"], shell = True, cwd = "path\to\file") open.terminate() 我还尝试了open.kill()、os.kill(open.pid,0)和os.system(“TASKKILL/IM/F fi

我正在使用Python3.5和Windows7。我正在尝试打开一个exe文件,然后终止它。我成功地打开了它,但无法关闭它。以下是我的代码的缩写版本:

from subprocess import Popen

open = Popen(["filename"], shell = True, cwd = "path\to\file")
open.terminate()
我还尝试了open.kill()、os.kill(open.pid,0)和os.system(“TASKKILL/IM/F filename.exe”)。我还发现一篇帖子建议不要使用shell=True,但没有它我无法让Popen工作。这些选项都不会抛出错误,只是不会关闭我打开的文件


我在网上发现了类似的错误,但似乎没有具体的解决办法。我读到的潜在解决方案(上面列出的最常见的)对我来说并不适用。有解决方法吗?

事实证明,shell=False是实现此功能所必需的。以下是我的成功代码:

open = Popen(["path\to\file\filename"])
open.terminate()