Search code examples
pythonterminate

python code that will terminate another process (chrome.exe for example) on user imput?


I was wondering if any of you know how to create a python code that would terminate a certain process, im thinking a list of them (chrome.exe, Microsoft edge, etc) if the program gets user input. Is this even possible? The idea is that the python code will be reading a text file for certain words or phrases the user inputs and if detected, it will terminate (or crash) the other program. I am relatively new to the world of python so please go easy on me. Thanks!


Solution

  • Here is the code:

    import os
    
    os.system("tasklist > 1.csv")
    with open("1.csv", "r") as f:
        print(f.read())
    task = input("Enter process: ")
    os.system("taskkill /f /im "+task)