简体   繁体   English

输入两个程序之间的输出通信

[英]Input output communication between two programs

I have a third party java program called kgsgtp.jar which need to communicate with my own C++ (but mainly just C) program. 我有一个名为kgsgtp.jar的第三方java程序,需要与我自己的C ++(但主要是C)程序进行通信。 The documentation for the java program states: java程序的文档说明:

===================== =====================

You just need to make sure that stdin for kgsGtp it connected to the engine's output and stdout for kgsGtp is connected to the engine's input. 你只需要确保kgsGtp的stdin连接到引擎的输出,而kgsGtp的stdout连接到引擎的输入。 Usually, the easiest way to do this is by forking and execing kgsGtp from within your engine. 通常,最简单的方法是在引擎内分叉和执行kgsGtp。

===================== =====================

Now I am a reasonably competent programmer and feel that I could probably arrange all that, given just a few more clues. 现在我是一个相当称职的程序员,并且觉得我可以安排所有这些,仅仅提供一些线索。 I suspect that if the description was expanded to erm, 10? 我怀疑如果描述扩展到erm,10? lines instead of three and a half then I'd have it sorted in no time. 线条而不是三个半,然后我立即对它进行排序。

I'm guessing that what the document means by forking, is using WinExec() or CreateProcess() in my program to execute the java program? 我猜这个文件通过分叉意味着什么,在我的程序中使用WinExec()或CreateProcess()来执行java程序? I'm also guessing that perhaps when I use the right function, then the fact of one program's stdin corresponding to the other's stdout will happen automatically? 我也猜测也许当我使用正确的函数时,一个程序的stdin对应另一个stdout的事实会自动发生吗?

That description is for unixes, where a sequence of pipe(),dup2(), fork()/exec() calls would be use to do this. 该描述适用于unixes,其中将使用一系列pipe(),dup2(),fork()/ exec()调用来执行此操作。

Take a look at the code snippet in the answer from denis here: How do I get console output in C++ with a Windows program? 看看denis的答案中的代码片段: 如何使用Windows程序在C ++中获得控制台输出? , should get you started. ,应该让你开始。

Edit: more complete example is here: http://support.microsoft.com/kb/190351 编辑:更完整的示例在这里: http//support.microsoft.com/kb/190351

你需要的是相当于Windows上的POSIX dup()可能是这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM