tags:

views:

75

answers:

2

I have a third party java program called kgsgtp.jar which need to communicate with my own C++ (but mainly just C) program. The documentation for the java program states:

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

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. Usually, the easiest way to do this is by forking and execing kgsGtp from within your engine.

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

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? 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? 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?

A: 

What you need is equivalent of POSIX dup() on windows may be this

Neeraj
+3  A: 

That description is for unixes, where a sequence of pipe(),dup2(), fork()/exec() calls would be use to do this.

Take a look at the code snippet in the answer from denis here: http://stackoverflow.com/questions/191842/how-do-i-get-console-output-in-c-with-a-windows-program , should get you started.

Edit: more complete example is here: http://support.microsoft.com/kb/190351

Anonym
That looks promising... let me just double check I'm understanding this. In his code, when you reach the comment "//readfile and/or writefile"... does that mean that from now on any printf()'s I do will go to the stdin of teste.exe and vice versa?
Mick
No, it means reading from the hRead handle reads from stdout/err of teste.exe. The example there doesn't hook up stdin of teste.exe, but it would be similar - create another pipe and set the hStdInput in the STARTUPINFO structure. Added a link to another example .
Anonym
Thanks for your help.
Mick