From a54c92d7fbbb6531569cfa6431e5219f6eba2c01 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sat, 10 Sep 2011 11:36:59 -1000 Subject: [PATCH] check the registry on win32 to find out where java.exe is kept --- infiniteworld.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/infiniteworld.py b/infiniteworld.py index 8494562..97455f9 100644 --- a/infiniteworld.py +++ b/infiniteworld.py @@ -218,11 +218,37 @@ class MCServerChunkGenerator(object): """ defaultJarStorage = None + if sys.platform == "win32": javaExe = which("java.exe") + javaExe = None + if javaExe is None: + KEY_NAME = "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" + try: + p = subprocess.Popen(["REG", "QUERY", KEY_NAME, "/v", "CurrentVersion"], stdout=subprocess.PIPE, universal_newlines=True) + o, e = p.communicate() + lines = o.split("\n") + for l in lines: + l = l.strip() + if l.startswith("CurrentVersion"): + words = l.split(None, 2) + version = words[-1] + p = subprocess.Popen(["REG", "QUERY", KEY_NAME + "\\" + version, "/v", "JavaHome"], stdout=subprocess.PIPE, universal_newlines=True) + o, e = p.communicate() + lines = o.split("\n") + for l in lines: + l = l.strip() + if l.startswith("JavaHome"): + w = l.split(None, 2) + javaHome = w[-1] + javaExe = os.path.join(javaHome, "bin", "java.exe") + print "RegQuery: java.exe found at ", javaExe + break + + except Exception, e: + print "Error while locating java.exe using the Registry: ", repr(e) else: javaExe = which("java") - jarStorage = None tempWorldCache = {}