The output line is in standard output or standard error descriptor (1 or 2, respectively).
You should redirect these streams (take a look at the dup and dup2 functions) to the place where you can read them (e.g. POSIX pipe ).
In C, I would do something like this:
int pd[2]; int retValue; char buffer[MAXBUF] = {0}; pipe(pd); dup2(pd[1],1); retValue = system("your command"); read(pd[0], buffer, MAXBUF);
Now you have (part) of your output in the buffer and the return code in retValue.
Alternatively, you can use the function from exec (i.e. execve ) and get the return value using wait or waitpid .
Update: this will redirect only standard output. To redirect the standard error, use dup2(pd[1],1) .
source share