You are trying to solve a classic and small problem with a very hard approach. You have several ways to solve it:
- Instead of a console app, use a GUI, and create several windows. All major libraries like Qt and GTK support this.
- Write to several file handles and launch several xterm (or gnome-terminal, or any other one that is present on your system) instances and cat, tail or less those outputs on these terminals.
- Have multiple gateways, like listening on TCP ports, and have multiple text mode clients that connect to these gateways. You could also telnet to TCP servers which are very easy to implement. CORBA and Shared Memory are also very good, in fact all IPC mechanisms, are to be used in similar cases too, but most of the IPC mechanisms seem to be too much for what you want to do (you just want to show some logs).
The second one is more or less the most efficient and easily implemented. For more information you need to tell us more about what you are doing and what is your toolchain. But in all of these solutions (except the first one), there are multiple processes. If I have understood your question correctly, you are aiming for a single process solution, which I think is a very hard way of solving your problem.
Ok you are using cpp, I would suggest opening several fstreams for your different outputs, like this maybe
FILE* f = fopen("/path/to/one/file", "w+");
std::fstream myStream(f);
myStream << "Hello World
";
Then launch several processes of xterm with the shell command that outputs those files, like:
tail -f /path/to/one/file
which would make it like:
system("gnome-terminal -x sh -c 'tail -f /path/to/one/file'");
or
system("xterm -e 'sh -c "tail -f /path/to/one/file"'");
or maybe even
system("xterm -e 'tail -f /path/to/one/file'");
do this for each output once and you are done. Just continue writing to those fstreams and they will each be shown in one of the consoles.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…