Created
April 23, 2019 07:43
-
-
Save grahampugh/dcb3023afaf9a9c799d6c7b456a0e6db to your computer and use it in GitHub Desktop.
Print the JDK latest version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
### JDK Version identifier | |
def version(): | |
"""Returns the latest installed jdk version""" | |
import subprocess | |
import plistlib | |
jdk_home_output = "/usr/libexec/java_home -X" | |
java_arch = "x86_64" | |
process = subprocess.check_output(jdk_home_output.split()) | |
jdk_version_plist = plistlib.readPlistFromString(process) | |
i = 0 | |
while i < len(jdk_version_plist): | |
if jdk_version_plist[i]["JVMArch"] == java_arch: | |
jdk_version = jdk_version_plist[i]["JVMVersion"] | |
break | |
i += 1 | |
try: | |
jdk_version | |
except NameError: | |
jdk_version = "" | |
return jdk_version | |
script_version = version() | |
### End Version identifier | |
print script_version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment