I'm sorry, I feel like this is DEFINITELY a newbie question but as I'm just getting back into c++ I guess that sits me squarely in the newb category.
So I'm writing some basic code to collect some quick info on a host machine and (eventually) I want to have it dump the output of its function into a text or csv file to make it easy to upload into a spreadsheet.
With help from other internet strangers, I've managed to write some functions using the system() command that grabs hostname, IP address, MAC address, Default route, and Subnet mask, and it outputs that to the screen but it doesn't seem to store it in the variable I've defined for it. Its strange, with my understanding of variables I figured this would work.
For example, to get the hostname I'm running this code:
char cmd[256];
strcpy(cmd,"hostname");
hostname = system(cmd);
cout << endl;
My thinking was that since I was telling the program that my variable hostname was equal to the output of the command system(cmd) that it would store the output of that command as the value of the variable. I tested it though by having it cout the variables after running these functions and it just spits out blank lines.
Maybe I'm not understanding the way system() sending output?
Oh! I suppose its worth mentioning that I'm writing this on a Linux Mint machine but will have to adapt this later to use windows commands. I don't think that matters until after I solve this issue though.
Well, I started with a line of code that simply said
hostname = system(hostname);
but that wouldn't compile just threw up errors. I tried with system("hostname") as well. I tried a couple other variations of this as well. I also looked into the libraries that are needed to be included, found a couple that still needed to be included, but that didn't work either. eventually I started trying different codes from other people on forums and websites using the system() calls until I landed on the code that I pout above. It got me the farthest because it at least works to print the info I need but that about it.
Anyways, thanks in advance for the help, and sorry for the ramblingness!