Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

nim-lang

I'm looking for something similar to python's sys.platform, which returns 'linux', 'windows', etc, or even better, something like python's platform module which gives you the operating system, distribution, release version, etc.

like image 842
Ben Doan Avatar asked Nov 05 '25 11:11

Ben Doan


1 Answers

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

This prints on my system:

I'm on Linux!
amd64 specific code!
Such a modern Nim version!
OS: linux, CPU: amd64, cpuEndian: littleEndian, NimVersion: 0.10.3
like image 70
def- Avatar answered Nov 09 '25 08:11

def-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!