如何用python杀死一个批处理文件?

问题描述 投票:0回答:1

I need your help please and Thanks ♥

p = subprocess.Popen(str(filepath), shell=True, stdout = subprocess.PIPE)

How could I stop a running file or kill it (.bat file) ? I used a code in function to open it : p = subprocess.Popen(str(filepath), shell=True, stdout = subprocess.PIPE) so I want to make another ...

p = subprocess.Popen('exit ' + str(filepath), shell=True, stdout = subprocess.PIPE)

In terminal to close a opened programe you can use:

taskkill
python python-3.x batch-file file-handling popen
1个回答
0
投票

我试过这样的事情:IM AppName >nul例如 taskkill IM notepad++.exe >nul。现在你可以使用os库来输入。

os.system(f'cmd /c "taskkill /IM notepad++.exe >nul"')
© www.soinside.com 2019 - 2024. All rights reserved.