如何使用命令行界面与不相关的进程进行通信?

发布于 2024-08-28 05:32:43 字数 264 浏览 6 评论 0原文

我正在尝试在 Linux 中编写一个 C++ 程序,通过命令行界面与国际象棋引擎进行通信。国际象棋引擎有标准协议,例如 UCI 所以,如果我能写这个,我就可以使用不同的国际象棋发动机可互换。

我的 C++ 程序应该启动国际象棋引擎,向其发送命令,获取输出,向其发送命令,获取输出,等等...这是如何完成的?

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 output, send it a command, get the output, etc... How is this done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡渣熟男 2024-09-04 05:32:43

您需要从标准输入和标准输出设置一些管道。默认情况下,程序的标准输出写入终端,标准输入从终端读取。本质上,您要做的就是将它们从终端重新路由到您的程序。

您可以分叉,设置管道,然后从子进程中使用 execve() 启动国际象棋。该站点有一个简单的示例,说明如何将主程序的标准输出传输到子进程的标准输入:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文