开发者

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

开发者 https://www.devze.com 2022-12-26 15:40 出处:网络
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 UCIso, if I could write this, I could use d

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

精彩评论

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