I had troubles with spawning processes and reading or writing to their stream, but then I discovered a great C++ library which is very very convenient.
This open-source project is called tiny-process-library and was created by eidheim (a big thanks to him).
A small platform independent library making it simple to create and
stop new processes in C++, as well as writing to stdin and reading
from stdout and stderr of a new process.
Features
- No external dependencies
- Simple to use
- Platform independent
- Read separately from stout and stderr using anonymous functions
- Write to stdin
- Kill a running process (SIGTERM is supported on Unix-like systems)
- Correctly closes file descriptors/handles
I am sharing this here because I first come to this thread before finding the library several hours later, so I hope it can save some time for further readers.