Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why does bufsize=1 not work in subprocess.Popen ?

Reply
Thread Tools

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

 
 
I. Myself
Guest
Posts: n/a
 
      04-29-2006
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


 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      04-29-2006
In <V6R4g.89900$P01.79112@pd7tw3no>, I. Myself wrote:

> 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
 
Reply With Quote
 
 
 
 
I. Myself
Guest
Posts: n/a
 
      04-29-2006
Marc 'BlackJack' Rintsch wrote:
> In <V6R4g.89900$P01.79112@pd7tw3no>, I. Myself wrote:
>
>
>> 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
>

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM
Why does post or pre incremenent or decrement does not work inside a sizeof operator? Tarun C Programming 5 07-14-2005 03:58 PM
Why does this (very simple piece of) code does not work? jblazi Python 5 08-16-2004 01:30 PM



Advertisments