I need to run the Linux CLI command and get its stdout output from C.
I can use pipe () to create a pipe, then fork / exec, redirect the descriptor of the child stdout to the pipe before calling exec (), and read from the pipe in the parent. In addition, I will need to wait for the baby.
Is there a simple call for fork + redirect + exec + wait, for example, system () makes fork + exec + wait, only system () does not redirect.
There's popen (), which does fork + redirect + exec, but does not wait, so I cannot get the exit status.
source
share