When using the system() function in C code, it appears that in many cases that it doesn't provide errno results but exit codes or simply writes to stdout and stderr.
My question is how can I get the results from system() before they go to stdout or stderr? Can the output be piped to a C function. I read this MS document provided in this question but am not sure.
I think stdout and stderr can be redirected to a file and read from there but is there a better way to capture the output?
Also, is the text file layout consistent between OS versions, and where can that information be found?
For a simple example, could the results of system( "dir > dirList" ) be programmatically captured in C to build a custom listing? I know that there is are readdir() and stat() in the dirent.h header to get this information but it's just an example to illustrate.
Thank you.