Ben Doan
Ben Doan

Reputation: 53

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

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.

Upvotes: 4

Views: 1538

Answers (1)

def-
def-

Reputation: 5393

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

Upvotes: 13

Related Questions