开发者

How do I communicate with an unrelated process using its command line interface?

I'm trying to write a C++ program in Linux that communicates with a chess engine via its command line interface. Chess engines have standard protocols like UCI so, if I could write this, I could use different chess engines interchangeably.

My C++ program should start the chess engine, send it a command, get the 开发者_StackOverflowoutput, send it a command, get the output, etc... How is this done?


You'll need to set up some pipes from standard in and standard out. By default, standard out from a program is written to the terminal and standard in is read from the terminal. Essentially what you'll be doing is re-routing these from the terminal to your program.

You can fork, set up the pipes, and then launch chess with execve() from your child process. This site has a simple example of how to pipe standard out from your main program to standard in of a child process:

http://www.cim.mcgill.ca/~franco/OpSys-304-427/messages/node92.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜