smitz
smitz

Reputation: 59

stdout to a variable c/c++

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.

Upvotes: 1

Views: 2082

Answers (1)

First, you don't need to run the uname command programmatically to get your processor. You can simply run the uname(2) syscall (which the uname command invokes). And you could also read and parse /proc/cpuinfo from 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.

Upvotes: 4

Related Questions