Answers.Body: <p>The code required for this is platform dependent, so it may be pragmatic to use a third party API to handle inter-process communication for you. Boost provides <a href="https://www.boost.org/doc/libs/1_64_0/doc/html/process.html" rel="noreferrer"><code>Boost.Process</code></a> and Qt provides <code>QtProcess</code>, both of which allow for communication via stdin and stdout. </p>
  
  <p>Otherwise, you will have to directly interact with platform specific APIs, such as <code>CreateProcess</code> on Windows and <code>fork</code>, <code>pipe</code>, etc. on Linux.</p>
  
  <p>Once you are able to communicate with the engine, you just need to follow the <a href="http://wbec-ridderkerk.nl/html/UCIProtocol.html" rel="noreferrer">UCI Protocol</a> (which is used by Stockfish) to communicate with the engine.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-16T15:47:08.693Z
Answers.Text: Are these methods how most GUI interact with stockfish?
Answers.UserDisplayName: Reuben Walker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-16T15:55:56.167Z
Answers.Text: CuteChess, for example, uses the Windows API to interact with engines on windows and QtProcess on other operating systems.
Answers.UserDisplayName: konsolas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-16T15:15:00.630Z
Answers.LastActivityDate: 2019-10-16T15:15:00.630Z
Answers.UserDisplayName: konsolas
Body: <p>I am looking for a way to have my C++ program communicate with Stockfish. An ideal solution would use the compiled version and my program would send commands to the .exe which would return the results. I have looked extensively and have come across suggestions for pipes or the use of the system function but I am not sure how either of those work and if it's possible to have information returned to my C++ program. I am running on Windows. Any suggestions on what method to use and direction on how to apply that method would be greatly appreciated.</p>
  
Tags: <software><stockfish>
Title: What is the best way to interface with Stockfish in a C++ program?
ThreadText: # What is the best way to interface with Stockfish in a C++ program?
  
  (Asked by: username_0 on 2019-10-16)
  
  I am looking for a way to have my C++ program communicate with Stockfish. An ideal solution would use the compiled version and my program would send commands to the .exe which would return the results. I have looked extensively and have come across suggestions for pipes or the use of the system function but I am not sure how either of those work and if it's possible to have information returned to my C++ program. I am running on Windows. Any suggestions on what method to use and direction on how to apply that method would be greatly appreciated.
  
  **Tags:** software, stockfish
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-16. Score: 5 | Accepted answer
  
  The code required for this is platform dependent, so it may be pragmatic to use a third party API to handle inter-process communication for you. Boost provides [`Boost.Process`](https://www.boost.org/doc/libs/1_64_0/doc/html/process.html) and Qt provides `QtProcess`, both of which allow for communication via stdin and stdout.
  
  Otherwise, you will have to directly interact with platform specific APIs, such as `CreateProcess` on Windows and `fork`, `pipe`, etc. on Linux.
  
  Once you are able to communicate with the engine, you just need to follow the [UCI Protocol](http://wbec-ridderkerk.nl/html/UCIProtocol.html) (which is used by Stockfish) to communicate with the engine.
  
  > **Comments:**
  > **username_0**: Are these methods how most GUI interact with stockfish?  
  > **username_1**: CuteChess, for example, uses the Windows API to interact with engines on windows and QtProcess on other operating systems.  
  
  ---
  
  