Araq / malebolgia

Malebolgia creates new spawns. Structured concurrency. Thread pools and related APIs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to feed commands to external process and catch output

tissatussa opened this issue · comments

i just found your library and i think it can solve my problem : i tried to start a process (a chess engine) in Nim and feed commands to it (stdin) and catch its output (stdout) .. i managed to get this working somehow but my solution seems primitive and incomplete, see https://forum.nim-lang.org/t/10613

when i execute the process 'stockfish' in terminal, the program returns its 'bestmove' but my Nim script doesn't output this last line !? I read about Nim threads, threadpools, async, await, spawn but it i don't find good examples and so it's all too difficult for me ..

can anybody give a (simple) example? Just feed commands to an external process and catch its output? It seems Malebolgia can do this easily, but i have no clue .. eventually i want to build a GUI app which uses the output info of such chess engine to calculate things and output a graph, while the engine is still running; eg. the engine process also has to listen to a "stop" command ..

Read https://github.com/Araq/nimedit/blob/master/console.nim#L318 for inspiration.

Having said that, you're better off using a library instead of an external process, interprocess communication is usually a clusterfuck on UNIX.