Search code examples
c++pipeexeinteraction

Reading input from .exe and writing to a .exe for reading Chess engine commands


I am searching all day for an example c++ program which will use ready .exe file which has as an output strings and then waits for standart input and again prints outputs and so on and so forth.

For example my c++ program will use standard output to write "uci" to a .exe program, the .exe program will reply with a string again which I will be able to read in my c++ program and again I will send a new string and will wait for a reply by the .exe.

I found something about pipes but I thought they were really difficult to understand.Is there any ready library/interface I could use? Or any example you can give me with pipes?


Solution

  • If you open to use bigger frameworks, there is an easy to use class in Qt to handle processes: http://doc.qt.io/qt-5/qprocess.html.

    QProcess exe;
    exe.start("foo.exe");
    exe.write("uci");
    exe.waitForReadyRead();
    auto result = exe.readAll();
    

    On windows you can use CreateProcess/CreatePipe, but the code will be a lot more verbose. Example: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx