zulqarnain
zulqarnain

Reputation: 1735

Get details of installed java version using python

I am trying to use subprocess to check if java is installed and also check if it's the right version. From the documentation you can map the output to variable and be able to use but it's not working for java. For example when I do li = subprocess.check_output(["ls", "-la", "."]) I get the output stored in li and nothing is shown on the console. But when I do jd = subprocess.check_output(["java", "-version"]) this is what is shown on the terminal

java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

and jd is empty.

Upvotes: 1

Views: 1010

Answers (1)

jh314
jh314

Reputation: 27792

You can store the results into jd by capturing standard error in the result to stdout:

jd = subprocess.check_output(["java", "-version"],
              stderr=subprocess.STDOUT)

Upvotes: 2

Related Questions