[python-win32] win32pipe and buffer size
Frank Guenther
xeoicq at netscape.net
Tue Jul 12 10:41:16 CEST 2005
Thanks for the reply, but it seems I run into the same problem like
before when I use the subprocess module.
I modified your example in the following way:
---- echo.py
import sys
if __name__ == '__main__':
while 1:
indata = sys.stdin.readline()
if indata=='end\n': break
sys.stdout.write( 'echo>'+indata)
sys.stdout.flush() #!!!!!!!!!!!! don't work without
---- caller.py
import subprocess
if __name__ == '__main__':
child = subprocess.Popen(
['python', 'echo.py'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE
)
i=1
while i<10:
child.stdin.write('spam'+str(i)+'\n')
data = child.stdout.readline()
print data
i+=1
child.stdin.write('end\n')
Now the problem arises if I comment line 8 "sys.stdout.flush()" or
replace line 7 and 8 by "print 'echo>'+indata"
The tool I try to automate has the same behavior.
But there must be a way to get the text that is printed by the tool.
Is it necessary to use more low-level access and in which way,
win32file, etc... ?
Tschau,
Frank
kveretennicov at gmail.com wrote:
>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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20050712/922344e0/attachment.htm
More information about the Python-win32
mailing list