Jython how to get the name of the operating system

How to determine the base OS, jython works. Not 'java', but 'nt' or 'posix'.

  • platform.platform
  • os.name
  • and sys.platform only return 'java'
+4
source share
1 answer

For jython, I use java.lang.System.getProperty("os.name"):

import sys

def get_os_version():
    ver = sys.platform.lower()
    if ver.startswith('java'):
        import java.lang
        ver = java.lang.System.getProperty("os.name").lower()
    return ver

print(get_os_version())
+6
source

Source: https://habr.com/ru/post/1538627/


All Articles