Reputation: 19233
I'm using subprocess.call
, and I need to get the output for stdout and stderr. How can I do this?
Notice check_output():
Note Do not use stdout=PIPE or stderr=PIPE with this function. As the pipes are not being read in the current process, the child process may block if it generates enough output to a pipe to fill up the OS pipe buffer.
My call might produce a lot of output, so what would be a safe way to get the output?
Upvotes: 0
Views: 143
Reputation: 4399
Something like this would work:
f = file('output.txt','w')
g = file('err.txt','w')
p = subprocess.Popen(cmd, shell=True, stdout=f, stderr=g)
f.close()
g.close()
Upvotes: 1
Reputation: 43553
Create a file object opened for writing and pass that as sdtout
and stderr
.
Upvotes: 0