1

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.

1
  • 1
    java -version prints to stderr, not stdout. Commented Jul 16, 2013 at 18:29

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it works. Sometimes documentation is just not clear/enough for newbies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.