[python-win32] win32pipe and buffer size

Konstantin Veretennicov kveretennicov at gmail.com
Tue Jul 12 04:38:02 CEST 2005


On 7/11/05, Frank Guenther <xeoicq at netscape.net> wrote:
> Hi All,
> 
> I try to automate a command line tool and have the problem that I can't
> read the stdout-pipe.
> I think the reason is the tool doesn't flush the pipe so  it is first
> readable when the process was closed.
> Can I set the buffer size of the stdout-pipe by win32pipe to force the
> tool to write to the pipe?
> 
> Is there a possibility to use win32file to get a low-level access to the
> pipes or some other solution to the problem?

Have you tried standard subprocess module? It uses unbuffered i/o by default.

> I would be thankful for some hints and example code.

Hope this helps:

---- echo.py

import sys

if __name__ == '__main__':
    print 'echo>',
    print sys.stdin.readline()

---- caller.py

import subprocess

if __name__ == '__main__':
    child = subprocess.Popen(
        ['python', 'echo.py'],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE
        )
    child.stdin.write('spam\n')
    print 'received:', child.stdout.readline()
    child.wait()

- kv


More information about the Python-win32 mailing list