Problem with pipes (win32pipe)

RPM1 rpm1deletethis at frontiernet.net
Mon Dec 3 18:44:01 EST 2001


I'm no expert but I have been struggling with popen2 a bit myself.
I think I've figured out that you can use the os module and the stat
module to help figure out when an input pipe has something in it.

first:

import stat
import os

then you can see how many bytes are in the pipe by doing this:

count = os.ftstat(fin.fileno())[stat.ST_SIZE]

using a separate thread to read the data into a buffer when there
is something in the pipe might help too.  Maybe someone else
can give more definitive answers.

I've found that I can only open one set of pipes in Windows 9x
at a time.  If I open multiple sets of pipes the last one that I close
hangs.  Windows NT doesn't have this problem.

Also if the app you're calling is a 16 bit app, you may need to
create a dummy C app to create 32 bit standard handles to pass
to your app.  Search Google for Python and Bill Tutt to find posts
about this issue.

Sorry I can't help more.  I haven't gotten much help myself with popen2
on Windows here.  I believe Unix doesn't have any of these issues.

Good luck,
    Patrick

p.s. Please post any good info on Windows popen that you get.



"Jeremy Gibson" <augspies at charter.net> wrote in message
news:AE0A765CAD7C795A.6D9D4CCEA6456F4D.5012B73D9CEA4F92 at lp.airnews.net...
> I am having a bear of a time trying to get my python program to talk to a
> windows process.  The program I am trying to run is call nrcmd.  It is a
> cisco program that is used for administering router clusters.
>
> Here is what I have done so far(BTW) the kludgey readlines are going to
> be replaced with some pattern matching I just wanted to get talking first.
>
> *****************************************************
> import os, win32pipe
> os.chdir('c:\\program files\\network registrar\\bin')
> fin, fout = win32pipe.popen2('nrcmd')
> c = 0
> while c < 6:
> fout.readline()
> c = c+1
> fout.read(7)
> *****************************************************
>
> The output from this is:
> *****************************************************
> 100 Ok\n
> cluster = nnn.nnn.nnn.nnn\n
> default-format = user\n
> user-name = user \n
> visibility = 5\n
> nrcmd>
> *****************************************************
>
> At this point any fin.write() will be accepted without complaint, but
> nothing is happening.  If I attpempt to fout.read() again the program
> hangs and must be killed.  I assume this is happening because I am
> attempting to read a null byte. The return from a successfull (or
> unsuccessfull) write should fill the fout buffer with something to read.
>
> I am sending newlines in the fin.writes I've tried and I've even tried
> sending \r\n since this is a windows machine I'm working with.  I've also
> tried fin.flush() after a write.
>
> If anyone has any ideas or thoughts on where I might find illumination
> for this problem please write to my email, or post to the group.
>
> Thanks,
> Jeremy Gibson





More information about the Python-list mailing list