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

Discussion in 'Python' started by I. Myself, Apr 29, 2006.

  1. I. Myself

    I. Myself Guest

    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
     
    I. Myself, Apr 29, 2006
    #1
    1. Advertising

  2. 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
     
    Marc 'BlackJack' Rintsch, Apr 29, 2006
    #2
    1. Advertising

  3. I. Myself

    I. Myself Guest

    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
     
    I. Myself, Apr 30, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Hudgins

    popen bufsize not allowed on windows

    Jonathan Hudgins, Jul 24, 2004, in forum: Python
    Replies:
    1
    Views:
    368
    Jonathan Hudgins
    Jul 25, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,076
    Smokey Grindel
    Dec 2, 2006
  3. =?iso-8859-1?B?aWFuYXLp?=

    real time updating of popen, bufsize=0 problems

    =?iso-8859-1?B?aWFuYXLp?=, Apr 6, 2007, in forum: Python
    Replies:
    4
    Views:
    582
    =?iso-8859-1?B?aWFuYXLp?=
    Apr 6, 2007
  4. Steven K. Wong
    Replies:
    6
    Views:
    1,053
    Nobody
    Jan 10, 2010
  5. bufsize in subprocess

    , Jan 22, 2012, in forum: Python
    Replies:
    3
    Views:
    645
Loading...

Share This Page