I am making a program to do a bit of process management for me on windows 10.
In order to kill unneeded processes I am using the following command:
import subprocess
subprocess.Popen("taskkill /F /im "+unwantedProcess, shell=True, stdout=subprocess.PIPE)
Where unwanted process is the full name of a process I want to kill. I have also tried using:
os.system("taskkill /F /im "+unwantedProcess)
Now this works fine when it is interpreted or compiled using pyinstaller. The problem comes when I use the
--noconsole
command in pyinstaller. It works in all other instances except when there in no console (since I do not want a console opened in the background). Any idea how to fix this?
Edit: After editing the code I inserted a very basic error catch statement as follows:
try:
subprocess.Popen("taskkill /F /im skype.exe", shell=True, stdout=subprocess.PIPE)
except Exception as e:
f = open("error.txt", "w")
f.write(str(e))
f.close()
Using skype as an example process to kill. It still killed it successfully when the program was interpreted or compiled with a console. However, when it was compiled using the
--noconsole
command once again I got this output in my error file:
[Error 6] The handle is invalid
Skype was definitely open when I ran this program