subprocess.Popen()/call() and appending file

hiral hiralsmaillist at gmail.com
Mon Jun 14 09:31:56 EDT 2010


Hi,

Do we have any facility to append file from Popen()/call(); see below
example...

1 import subprocess
2 f=open('log', 'w')
3 ...# writing some log-into into log file
4 p = subprocess.Popen(cmd, stdout=f, stderr=f) # (Q)
5 ...# do remaining stuff

Q: At line# 4, the output of the 'cmd' will wipe-out everything in
'log' file. So to avoid this do we have any mechanism to append into
the existing file from subprocess.

Currently I am doing following...
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
o, e = p.communicate()
print >> log, o
print >> log, e

Pleaese let me know if there is any better mechanism.

Thank you in advance.



More information about the Python-list mailing list