You will have to create a pipe and redirect the output from the system call to that pipe, and then read the data from the pipe -- this is what the popen call essentially does, which means that you should just convert the system
call to a popen
call and then read from the file descriptor into the variables you want to populate.
You can find examples on how to use popen on stack overflow, like this one here; linux command executing by popen on C code