popen on Win 9x?
PM
pmullh at yahoo.com
Fri Nov 16 10:55:14 EST 2001
"RPM1" <rpm1deletethis at frontiernet.net> wrote in message news:<tv928r6e9akvdd at corp.supernews.com>...
> Goal: Write a python program that can call two other C programs and interact
> with the stdin and stdout of the C programs on Win 98.
>
> The two C programs are chess programs that I won't have source to. I want
> the two programs to play against each other. I have been successful at
> using popen2 to act as stdin and stdout for either chess program separately
> but when I try to communicate with both I have problems when I close the
> second program's pipes. It leaves the process running and leaves a W9xpopen
> process going and at least one Winoldap process.
>
> I open the pipes to each program and then write and read the pipes, (using
> fstat and stat to determine how much data is in the pipes coming from the
> chess programs so I don't block). My program works on Windows NT but not on
> 98.
>
> Any thoughts?
>
> Thanks,
> Patrick
Here's the code:
======================
import string
import os
import stat
import time
def get_reply(p):
count = 0
while (count == 0):
count = os.fstat(p.fileno())[stat.ST_SIZE]
data = ''
while (count > 0 ):
data = data + p.read(1)
count = os.fstat(p.fileno())[stat.ST_SIZE]
return data
to_e1,from_e1 = os.popen2('d:\utils\yace\yace_09956\wb\yace')
to_e2,from_e2 = os.popen2('d:\utils\comet\comet_b37 / xboard')
to_e1.write('quit\n')
time.sleep(3)
print get_reply(from_e1)
to_e2.write('quit\n')
time.sleep(3)
print get_reply(from_e2)
from_e1.close()
to_e1.close()
from_e2.close()
to_e2.close()
=============================
I was able to run each chess program from python separately. I can
even run each program separately in separate DOS windows at the same
time.
Any help would be appreciated,
Thanks, Patrick
More information about the Python-list
mailing list