Search code examples
pythonconsolesubprocesspopen

Disable console output from subprocess.Popen in Python


I run Python 2.5 on Windows, and somewhere in the code I have

subprocess.Popen("taskkill /PID " + str(p.pid))

to kill IE window by pid. The problem is that without setting up piping in Popen I still get output to console - SUCCESS: The process with PID 2068 has been terminated. I debugged it to CreateProcess in subprocess.py, but can't go from there.

Anyone knows how to disable this?


Solution

  • fh = open("NUL","w")
    subprocess.Popen("taskkill /PID " + str(p.pid), stdout = fh, stderr = fh)
    fh.close()