I wrote some statements like below:
os.system(cmd) #do something
subprocess.call('taskkill /F /IM exename.exe')
both will pop up a console.
How can I stop it from popping up the console?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The process
STARTUPINFOcan hide the console window:Or set the creation flags to disable creating the window:
The above is still a console process with valid handles for console I/O (verified by calling
GetFileTypeon the handles returned byGetStdHandle). It just has no window and doesn’t inherit the parent’s console, if any.You can go a step farther by forcing the child to have no console at all:
In this case the child’s standard handles (i.e.
GetStdHandle) are 0, but you can set them to an open disk file or pipe such assubprocess.DEVNULL(3.3) orsubprocess.PIPE.