[Python-au] Processes and pipes; newbie alert

Jon john.windle at silverbrookresearch.com
Wed Dec 29 05:05:54 CET 2004


I have a program launchs a seperate processes and I can send commands to it
and get response back. But it is blocking and I'd like to be able to see if
there is a response ready before I try and read the pipe.

I think that win32pipe.PeekNamedPipe would do it but when I use it I get a
type error that says "TypeError: The object is not a PyHANDLE object". The
documentation seems sparse so after spending a bit of time playing. and
searched the archives with no joy so I thought I'd ask.

The code I'm using to is:

def gets(pipe):
    text = ""
    while 1:
          c = pipe.read(1)
          text = text + c
          if c == '\n': break
     return text


w = win32pipe.popen3('python slave.py', 't')
print w
w[0].write("s\n")

# I think the parameters are the pipe and the number of bytes to "peek"
print win32pipe.PeekNamedPipe(w1], 2)

result = gets(w[1])
print "Output = " + result

Obviously I don't need PeekNamedPipe here but I know the pipe has something
in it and wanted to try it out. The code all works fine if I comment out
PeekNamedPipe.

I haven't included the slave.py code as it seems unnecessary, it simply
watches stdin then append the received string to the processId and writes it
to standard out.

Running Python 2.2 and build 203 of pyWin.

I image it is something obvious I've missed.

Thanks in advance.

john




More information about the python-au mailing list