What you see is the output of the standard error, not the output of the standard output. Stderr redirection is controlled by the stderr constructor argument. By default, it is None , which means that the redirect does not occur, so you see this output.
It is generally recommended to store the output of stderr, as it helps debug and does not affect the normal redirection (for example, | and > redirecting the shell will not fix stderr by default). However, you can redirect it to another place the same way you do stdout:
sp = subprocess.Popen(listargs[0], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = sp.communicate()
Or you can simply remove stderr:
devnull = open(os.devnull, 'wb') #python >= 2.4 sp = subprocess.Popen(listargs[0], shell=False, stdout=subprocess.PIPE, stderr=devnull) #python 3.x: sp = subprocess.Popen(listargs[0], shell=False stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
Francis avila
source share