According to the question " How to get Linux distribution name and version? ", to get the linux distro name and version, this works:
lsb_release -a
On my system, it shows the needed output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic
Now, to get this info in C++, Qt4's QProcess would be a great option but since I am developing without Qt using std c++, I need to know how to get this info in standard C++, i.e. the stdout of the process, and also a way to parse the info.
Uptil now I am trying to use code from here but am stuck on function read().
Got it from cplusplus.com forums, a simple call
GetSystemOutput("/usr/bin/lsb_release -a")
works.For recent linux distros you can use following to get the OS info. The output is pretty standard and can be parsed using following spec:
https://www.freedesktop.org/software/systemd/man/os-release.html
Sample outputs:
It works for me
There are files named /etc/version and /etc/release which have information like whether you're using Ubuntu or Fedora, etc. (which is what the OP clarified his question to be).
You can simply use the function:
by including the header
It already returns the name & version as a part of the structure:
Am I missing something?