获取当前操作系统的最佳方式是什么?

What's the best way to get the current operating system?

我正在寻找类似于 python 的 sys.platform 的内容,其中 returns 'linux'、'windows' 等,甚至更好,类似于 python 的平台模块,它为您提供操作系统、发行版、发布版本等

when defined windows:
  echo "I'm on Windows!"
elif defined linux:
  echo "I'm on Linux!"
else:
  echo "I'm on some other platform!"

when defined x86:
  echo "x86 specific code!"
elif defined amd64:
  echo "amd64 specific code!"
else:
  echo "generic code!"

when (NimMajor,NimMinor,NimPatch) > (0,10,2):
  echo "Such a modern Nim version!"

echo "OS: ", hostOS, ", CPU: ", hostCPU, ", cpuEndian: ", cpuEndian, ", NimVersion: ", NimVersion

这在我的系统上打印:

I'm on Linux!
amd64 specific code!
Such a modern Nim version!
OS: linux, CPU: amd64, cpuEndian: littleEndian, NimVersion: 0.10.3