OS_VERSION Get operating system name and version.

Note: for Windows 11, need new-enough Java version to show Windows 11 instead of Windows 10.

Contents

Outputs

Ref: https://bugs.openjdk.org/browse/JDK-8274840

function [os, version, b] = os_version(backend)
arguments
  backend (1,:) string = ["sys", "python", "dotnet", "java"]
end

os = '';
version = '';

for b = backend
  switch b
    case "java"
      [os, version] = stdlib.java.os_version();
    case "dotnet"
      [os, version] = stdlib.dotnet.os_version();
    case "python"
      if stdlib.matlabOlderThan('R2022a'), continue, end
      [os, version] = stdlib.python.os_version();
    case "sys"
      [os, version] = stdlib.sys.os_version();
    otherwise
      error("stdlib:os_version:ValueError", "Unknown backend: %s", b)
  end

  if ~isempty(os) && ~isempty(version)
    return
  end
end

end