Skip to content

Commit 2d508c3

Browse files
author
Kush Jain
committed
fixed bug where java version was gathered incorrectly
1 parent e82f981 commit 2d508c3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mcoq.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import argparse
99
import sys
1010
import datetime
11+
import re
1112
import subprocess
1213

1314
HIDE_SUFFIX = " > /dev/null 2>&1"
@@ -192,12 +193,18 @@ def check_command(command, version):
192193

193194
def check_java_version():
194195
try:
195-
java_version = float(subprocess.check_output("java -version 2>&1 | awk -F[\\\"\.] -v OFS=. \'NR==1{print $2,$3}\'", shell=True))
196+
version = subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
197+
java_version = version.splitlines()[0].split("version")[1].split()[0].strip('"').split("_")[0].split(".")
198+
major = int(java_version[0])
199+
if len(java_version) < 2:
200+
minor = 0
201+
else:
202+
minor = int(java_version[1])
196203
except:
197204
print("Java is not installed, please install JDK. To install, please follow the steps at: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html")
198205
return False
199206

200-
is_incorrect_version = java_version < 1.8 or (java_version > 2 and java_version < 8)
207+
is_incorrect_version = (major < 1 and minor < 8) or (major > 2 and major < 8)
201208

202209
if is_incorrect_version:
203210
print("Incorrect version of Java installed. Please install Java 8 or later. For installation steps, please refer to: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html")

0 commit comments

Comments
 (0)