简体   繁体   English

TASKKILL特定的Python脚本

[英]TASKKILL specific Python script

I have a working TASKKILL command that kills python.exe using Process Name 我有一个有效的TASKKILL命令,该命令使用进程名称杀死python.exe

I'd like to narrow the scope of the command to kill a specific process (myScript.py) but can't use ProcessID as it changes with every run. 我想缩小命令范围以杀死特定进程(myScript.py),但不能使用ProcessID,因为它每次运行都会改变。

Is there a way I can add detail from the Command Line which knows the python script's name? 有没有办法我可以从知道Python脚本名称的命令行中添加详细信息?

Current Command: 当前命令:

Taskkill /IM python.exe /F >nul 2>&1
if errorlevel 1 (echo PYTHON.exe NOT FOUND) else (echo PYTHON.exe KILLED)

You might be able to kill it based on your Python script's memory usage. 您可能可以根据Python脚本的内存使用情况将其杀死。 In my case, the Python script is running a GUI, so the size gives it away. 在我的情况下,Python脚本正在运行GUI,因此大小将其释放。

taskkill /f /fi "IMAGENAME eq python.exe" /fi "MEMUSAGE gt 130000"

This reads as, forcefully kill the task ( taskkill /f ) identified by ( /fi ) the Python executable ( IMAGENAME eq python.exe ) which is using more than 130,000KB ( MEMUSAGE gt 130000 ) 1 . 读取为强制杀死( /fi )使用超过130,000KB( MEMUSAGE gt 1300001的Python可执行文件( IMAGENAME eq python.exe )标识的任务( taskkill /f )。

1 See taskkill /? 1看到taskkill /? for builtin help. 获得内置帮助。


NB You might find this SO post helpful: Find Windows PID of a python script with Windows Command Prompt . 注意:您可能会发现这篇SO帖子对您有所帮助: 使用Windows命令提示符查找python脚本的Windows PID Unfortunately, for me, It Doesn't Work™ but maybe you will have better luck. 不幸的是,对我来说,它行不通™,但也许您会遇到好运。

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

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