Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jython how to retrieve the operating system name

Tags:

jython

How to determin the underlying OS, jython is running on. Not 'java', but 'nt' or 'posix'.

  • platform.platform
  • os.name
  • and sys.platform only return 'java'
like image 993
Davoud Taghawi-Nejad Avatar asked Jan 10 '23 17:01

Davoud Taghawi-Nejad


1 Answers

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())
like image 58
Michał Niklas Avatar answered Mar 06 '23 16:03

Michał Niklas