I'm trying to make a program that launches the compiler and present its information (and later, some useful information on the errors) to the user in a pretty way. The first step would be to have a solution similar to 4coder's: The user presses a button and a program is compiled and the compilation information is displayed on the main program.
Based on the day 192's self-recompiling code, I could easily launch a process and compile a program using CreateProcess:
CreateProcess(command, command_line, 0, 0, FALSE, 0, 0, path, &startup_info, &process_info);
After some research I could direct the process' output to a file handle using the hStdOutput member of the STARTUPINFO struct.
Here are the most important points of the code.
HANDLE h = CreateFile("out.log", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, &sa, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
si.cb = sizeof(STARTUPINFO);
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdInput = NULL;
si.hStdError = h;
si.hStdOutput = h;
However, the objective is to interactively show the result like 4coder, so I would have to have it in a char buffer or something. Yeah, I could read the file but that seems really janky and slow.
Is there any way to capture the output of the child's process in a memory buffer of some sort so that I could display and analyze it however I want? It seems there are a lot of programs that do this, what is the best way to achieve it?
Thank you (and have a happy 2019) :),