Why does bufsize=1 not work in subprocess.Popen ?

I

I. Myself

I read in the docs that "bufsize=1" causes line buffering. (for
subprocess.Popen)

The following tiny program launches an executable file and then receives
its output. That works, but I want to
receive each line as it is ouput, not all of the lines at termination,
which is what is happening.
-------------------------------------------------------
from subprocess import Popen, PIPE
from os import remove, sep

p = Popen("." + sep + "myprogram", stdout=PIPE, bufsize=1)

while(1):
line = p.stdout.readline() # get next line
print line,
if line.count("terminator"):
break
------------------------------------------------------
How can I get line buffering?

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
 
M

Marc 'BlackJack' Rintsch

I read in the docs that "bufsize=1" causes line buffering. (for
subprocess.Popen)

The following tiny program launches an executable file and then receives
its output. That works, but I want to
receive each line as it is ouput, not all of the lines at termination,
which is what is happening.

From the Python side you can only control Python's input buffer but not
the output buffer of the external program you are starting. I guess that
programs buffers its output.

Ciao,
Marc 'BlackJack' Rintsch
 
I

I. Myself

Marc said:
From the Python side you can only control Python's input buffer but not
the output buffer of the external program you are starting. I guess that
programs buffers its output.

Ciao,
Marc 'BlackJack' Rintsch
That makes sense. I remember now that someone told me that Windows
sends line-by-line only to the screen. To a pipe it sends buffers full.

Thanks,

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top