Communicating with other programs (Win32)

Jan de Wit jwit@students.cs.uu.nl
Wed, 28 Nov 2001 15:38:15 +0100 (MET)


Hi all,

In my free time, I'm writing a Go program in Haskell. Main platform is 
GHC and GHCi under Win32. It is coming along nicely: it has a GUI and the
moves
it comes up with are starting to make some sense. For testing (and maybe
later
training :) purposes I want it to be able to play against GnuGo (the
strongest
Open Source Go program) on its own.

Currently, to get GnuGo to think up a move, I use something like (SGF is
the 
standard way of outputting Go games):

| do writeFile "in.sgf" (showAsSGF game)
|    let cmd = "echo quit > gnugo --quiet --infile in.sgf --color " ++
|              (show computerColor) ++ 
|              " --mode ascii > out.txt"
|    system cmd
|    result <- readFile "out.txt"
|    return (parseResultMove result)

I think this both ugly and inefficient: for every move a new instance of 
GnuGo gets started and an SGF file is output! Instead, I want 
to start GnuGo only once per game and communicate with it like a human
player 
would, by typing commands at it; or by using the Go Text Protocol which is 
specifically designed for computer-computer play.

Does anybody here know a way - under Win32 - to start a process in the 
background and communicate with it via its stdin/stdout? I've poked around 
a bit in the Win32 library source, looking for an FFI interface to 
CreateProcess (the API function which does what I want) but found nothing.
The Posix library looks like it should be up to the job, but 
unfortunately that isn't supported under Win32... (I'm not using Cygwin)

Any help would be appreciated!

Cheers, 
Jan de Wit