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 = ""
        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


[EMAIL PROTECTED] wrote:
On 7/11/05, Frank Guenther <[EMAIL PROTECTED]> 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
  
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to