Skip to content Skip to sidebar Skip to footer

Find Windows Pid Of A Python Script With Windows Command Prompt

I am running two different python scripts running on a windows machine simultaneously and would like to kill one but not the other from the command prompt. Using taskkill with the

Solution 1:

Using Get-WmiObject and PowerShell you can examine the command line arguments for each process, then pass the selected Process ID to taskkill.

This example shows how to kill a process executing the script test.py:

PSC:\Users\Administrator> taskkill.exe /F /PID $(Get-WmiObjectWin32_Process -Filter"name = 'python.exe'" | Where-Object {$_.CommandLine -like '*.\test.py'} | Select -ExpandPropertyProcessId)

Modify *.\test.py to match how you are actually calling each script, and it should work for you

Post a Comment for "Find Windows Pid Of A Python Script With Windows Command Prompt"