I’m wondering if it’s possible to kill a python script using C#.
In the small application I’m currently developing, a python application launches to localhost:portnumber. The portnumber of the application is always the same.
Is it possible, when the application is already running (I’m checking that by getting a list of ports currently in use), to kill it using some sort of command?
I’ve already found out that, in case it is not running, I can start the application using Process.Start();
You can use Process.Kill() to kill a specific process…
To find out which process to kill you can use
GetProcesses()and itterate through them…For example, here is how you can kill the calculator (calc.exe):
This will find all processes named “calc” and kill them.
In your case, If you already have a
Processobject (because you calledProcess.Start()) you can specifically kill that one using theKill()method.