简体   繁体   中英

TASKKILL specific Python script

I have a working TASKKILL command that kills python.exe using Process Name

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.

Is there a way I can add detail from the Command Line which knows the python script's name?

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. In my case, the Python script is running a GUI, so the size gives it away.

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 .

1 See taskkill /? for builtin help.


NB You might find this SO post helpful: Find Windows PID of a python script with Windows Command Prompt . Unfortunately, for me, It Doesn't Work™ but maybe you will have better luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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