stdout in subprocess

D'Arcy J.M. Cain darcy at druid.net
Wed Oct 27 17:22:51 EDT 2010


On Wed, 27 Oct 2010 16:24:29 -0400
Not To Miss <not.to.miss at gmail.com> wrote:
> 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.
> 
> ####### 1.py ##########
> from subprocess import *
> out = open('foo.t', 'w')
> a = Popen('ls -l', shell = True, stdout = out)

If you drop the "a = " part it will work.  If you need the object then
simply delete it (del a) when you are done with it.

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list