1

I want to make a wrapper around stockfish (chess engine) that uses UCI (Universal chess interface). Running stockfish from the terminal will open its shell:

Stockfish 8 64 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
|

(where I - cursor)
it waits input commands (like go, position, setoption, etc...)
I need to read output of e.g. go command.
It is the same if i wanted to receive select * from * connecting to database with mysql, psql or another DBMS executable or to read some output from python command using python executable
I'm using linux, but crossplatform solutions are more preferable

I tried to make a program using popen and fscanf in while loop but i guess i need something non-blocking current thread while waiting output from stdout

IC_
  • 1,624
  • 1
  • 23
  • 57
  • 1
    You can have your program create a pseudo-tty device on Linux, attach it to `stockfish`'s standard input and output, and be able to control it that way. `stockfish` thinks it's running in a terminal, but it's input and output comes from your program. This is a fairly advanced topic, that cannot really be explained in a brief paragraph or two on stackoverflow. You have a lot of reading and learning to do, if you want to implement something like that. This has nothing really to do with C++. – Sam Varshavchik Oct 22 '19 at 02:22
  • @samVarshavchik thanks for the reply, i thought it is pretty common task in c++ programming – IC_ Oct 22 '19 at 02:26
  • If you would like a portable solution, I would recommend python's subprocess module. You can create another process and communicate with it by subrpocess' functions. It's still a lot to learn, but you may start with this link. https://stackoverflow.com/questions/41542960/run-interactive-bash-with-popen-and-a-dedicated-tty-python – Bruce Shen Oct 22 '19 at 03:37
  • This question might help: https://stackoverflow.com/questions/5485923/launch-an-exe-process-with-stdin-stdout-and-stderr – GregHNZ Oct 22 '19 at 03:42
  • Search is your friend: – Max Vollmer Oct 22 '19 at 04:56
  • [Sending data to stdin of another process through linux terminal](https://stackoverflow.com/q/37424497/9199167) – Max Vollmer Oct 22 '19 at 04:56
  • [C/C++ - Run system(“process &”) and then write to its stdin](https://stackoverflow.com/questions/22430942/c-c-run-systemprocess-and-then-write-to-its-stdin) – Max Vollmer Oct 22 '19 at 04:56
  • [Redirect stdout of two processes to another process's stdin in Linux C](https://stackoverflow.com/questions/13041416/redirect-stdout-of-two-processes-to-another-processs-stdin-in-linux-c) – Max Vollmer Oct 22 '19 at 04:57
  • [Read another process' stdout in C++](https://stackoverflow.com/questions/4093252/read-another-process-stdout-in-c) – Max Vollmer Oct 22 '19 at 04:57
  • [How do i run a program from another program and pass data to it via stdin in c or c++?](https://stackoverflow.com/questions/21231188/how-do-i-run-a-program-from-another-program-and-pass-data-to-it-via-stdin-in-c-o) – Max Vollmer Oct 22 '19 at 04:57

0 Answers0