I am using int res = system("uname -p"); in my c++ code.
It will give the the result in standard output by using
fprintf(stdout,"execution returned %d.\n",res);
I want to store this result string in a variable, I am unable to store it.
I google it but unable to find proper solution, Can any one tell me the correct way.
First, you don’t need to run the
unamecommand programmatically to get your processor. You can simply run the uname(2) syscall (which theunamecommand invokes). And you could also read and parse/proc/cpuinfofrom your program.If you wanted to read the output of some command, use popen(3) library function.
See also my answer to a related question.