Is production: true
#windows #python

Title: Python Script to Search Kill Process

Created: 11 Mar 2025 Modified: 11 Mar 2025

Description: A simple snippet to find process by name and kill the process



import subprocess

output = subprocess.Popen('wmic process get processid,executablepath | find "msedgedriver.exe"', shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
pids = list(map(
    lambda it: it.strip().split(" ")[-1], 
    ( it for it in output.replace("\r\r\n", "\n").split("\n") if it != '')
))
pids
for pid in pids:
    print(f"Processing PID: {pid}")
    command = f"taskkill /f /pid {pid}"
    print(f"Execute command: {command}")
    result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
    print(f"Execute result: {result}")