What do I need to look at to see if I'm on Windows, Unix, etc?
Join Stack Overflow to learn, share knowledge, and build your career.
|
See: platform — Access to underlying platform’s identifying data |
|||||||||||||
|
|
If you are running macOS X and run |
||||
|
|
|
How about a new answer:
This would be the output if I was using OSX |
|||||
|
|
Sample code to differentiate OS's using python:
|
|||||||||||||||||
|
|
Use the |
||||
|
|
|
Dang -- lbrandy beat me to the punch, but that doesn't mean I can't provide you with the system results for Vista!
...and I can’t believe no one’s posted one for Windows 10 yet:
|
|||||||||
|
|
If you want user readable data but still detailed, you can use platform.platform()
Here's a few different possible calls you can make to identify where you are
The outputs of this script ran on a few different systems is available here: https://github.com/hpcugent/easybuild/wiki/OS_flavor_name_version |
||||
|
|
|
You can also use only platform module without importing os module to get all the information.
A nice and tidy layout for reporting purpose can be achieved using this line:
That gives this output:
What is missing usually is the operating system version but you should know if you are running windows, linux or mac a platform indipendent way is to use this test:
|
|||
|
|
|
Just for completeness, "OS" environment variable seems to be defined everywhere. On Windows XP/7/8/10 it is set to "Windows_NT". On Linux SuSE SP2 it is set to "x86-64 linux sles11[2]". I don't have access to OS-X or BSD machines, would be interesting to check there as well.
|
|||
|
|
|
For the record here's the results on Mac:
|
||||
|
|
|
Watch out if you're on Windows with Cygwin where
|
|||
|
|
|
try this:
and you can make it :
|
|||||||||
|
|
I am using the WLST tool that comes with weblogic, and it doesn't implement the platform package.
Apart from patching the system javaos.py (issue with os.system() on windows 2003 with jdk1.5) (which I can't do, I have to use weblogic out of the box), this is what I use:
|
||||
|
|
|
Check the available tests with module platform and print the answer out for your system:
|
|||
|
|
|
If you not looking for the kernel version etc, but looking for the linux distribution you may want to use the following in python2.6+
in python2.4
Obviously, this will work only if you are running this on linux. If you want to have more generic script across platforms, you can mix this with code samples given in other answers. |
||||
|
|
|
Interesting results on windows 8:
Edit: That's a bug |
|||
|
|
|
I do this
Docs here : sys.platform. Everything you need is probably in the sys module. |
||||
|
|
|
For Jython the only way to get os name I found is to check
|
|||
|
|
|
/usr/bin/python3.2
|
|||||||||
|
|
in the same vein....
|
|||||
|
|
|||
|
|
|
You can also use sys.platform if you already have imported sys and you don't want to import another module
|
|||||||||
|