>>> import subprocess
>>> f = open('txt', 'w+')
>>> p = subprocess.Popen(['dir'],stdout=f,stderr=f, shell=True)
>>> p.communicate()
(None, None) # stdout, stderr are empty. Same happens if I open a win32 gui app instead of python (don't think win32 gui apps set a stdout/stderr)
I want to retrieve the stdout or stderr of a subprocess
to test a few characteristics of them (not the current sys.__stdout__
). How can I do this from the python interpreter?
I think you are looking for
subprocess.PIPE
Example
As it can be seen,
is the stdout of the command and
is the stderr