<div>Hi all,</div><div><br></div><div>I have a question on subprocess.Popen, as shown comparably below. When I ran 1.py, it prints "0". I don't understand how the file is empty. Isn't it flushed when the file object "out" is closed? On the other hand, running 2.py prints correct value.</div>
<div><br></div><div>####### 1.py ##########</div>from subprocess import *<br clear="all"><div>out = open('foo.t', 'w')</div><div>a = Popen('ls -l', shell = True, stdout = out)</div><div>out.close()</div>
<div>print len(open('foo.t').readlines())</div><div><br></div><div><br></div><div>##### 2.py #########</div><div><div>from subprocess import *</div><div>out = open('foo.t', 'w')</div><div>a = Popen('ls -l', shell = True, stdout = PIPE, stderr = PIPE)</div>
<div>print >> out, a.communicate()[0]</div><div>out.close()</div><div>print len(open('foo.t').readlines())<br clear="all"><br></div><div><br></div><div>Thanks<br>-- <br>Best,<br>Zhenjiang<br>
<br>
</div></div>