Before nothing: I searched similar problems but none of the solutions seemed to work for me. Also please, I'm noob in C so sorry for the stupid mistakes that I can do. Thanks.
I have a little problem with my C++ file. What I want, is set a variable from a system("command"). I don't know if I'm explaining myself well so I put my file as an example. This is my file:
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int kernel = system("uname -a");
//Here It should print the value but instead of that prints a zero :/
printf("%d \n", kernel);
return 0;
}
I'm trying to define the variable "kernel" from the output of system("uname -a") command that should be something like:
$ uname -a
Linux 5.0.0-27-generic #28~18.04.1-Ubuntu SMP Thu Aug 22 03:00:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
However, when I try to execute the code the output is just:
0
I'm missing something or this cannot be done in C++? Sorry for the noob question.
Best regards.