tags:

views:

94

answers:

2
+1  Q: 

Getting OS version

Is there any function to get the OS type and version?

+2  A: 

I don't know about *nix I am afraid, but you could simply use io popen to obtain the result so for example on Windows the following will return the standard Windows Version information

local f = io.popen("ver") -- runs command
local l = f:read("*a") -- read output of command
print(l)
f:close()
Jane T
kk thanks...i will try to use uname -a on linux..that works :)
bofh
+2  A: 

uname of course prints out the kernel version, but if you want to know the distro version you could use lsb_release -a if it is available (check comment by Roman Cheplyaka).

local f = io.popen("lsb_release -a")
local s = f:read("*a")
f:close()
--# Do something with s...

The flow is the same as in the windows version.

ponzao
`/etc/issue` serves completely different purpose and is not guaranteed to contain version or even to have some predefined format (read `man 5 issue` for details). On LSB-conforming system you can use `lsb_release` command (try `lsb_release -a`). Note that in Debian you need to install package `lsb-release` in order to have this command. On Debian you can also analyse `/etc/debian_version` (that's what `lsb-release` does in Debian), most of the other distributions also have similar files.
Roman Cheplyaka
@Roman Yep you are right, thanks! I edited my answer.
ponzao