Debian Codegraph @

test/private/OSVersion.m

raw
1 function [formatted, OSType, OSVersion] = OSVersion()
2 % determines the OS type and its (kernel) version number
3 if ismac
4 OSType = 'Mac OS';
5 [dummy, OSVersion] = system('sw_vers -productVersion'); %#ok
6 % Output like "10.10.4" for OS X Yosemite
7
8 elseif ispc
9 OSType = 'Windows';
10 [dummy, rawVersion] = system('ver'); %#ok
11 % Output like "Microsoft Windows [Version 6.3.9600]" for Win8.1
12 pattern = '(?<=Version )[0-9.]+';
13 OSVersion = regexpi(rawVersion, pattern, 'match', 'once');
14
15 elseif isunix
16 [dummy, OSType] = system('uname -s'); %#ok
17 % This returns the kernal name
18 % e.g. "Linux" on Linux, "Darwin" on Mac, "SunOS" on Solaris
19 [dummy, OSVersion] = system('uname -r'); %#ok
20 % Returns the kernel version. Many Linux distributions
21 % include an identifier, e.g. "4.0.7-2-ARCH" on Arch Linux
22
23 % TODO: also use `lsb_release` in Linux for distro info
24 else
25 warning('OSVersion:UnknownOS', 'Could not recognize OS.');
26 OSType = 'Unknown OS';
27 OSVersion = '';
28
29 end
30
31 EOL = sprintf('\n');
32 OSType = strrep(OSType, EOL, '');
33 OSVersion = strrep(OSVersion, EOL, '');
34
35 formatted = strtrim([OSType ' ' OSVersion]);
36 end