Skip to content
Advertisement

Scripting in linux

Why java -version gives empty string when executing in subprocess.Popen. Is there any alternative to get the exact text given by java -version command in Linux?

version = ["java","-version"]

temp1 = subprocess.Popen(version, stdout=subprocess.PIPE)
ver = str(temp1.communicate())
print ver

Advertisement

Answer

I think you are getting some error so capture the stderr from the process.

version = ["java","-version"]
temp1=subprocess.Popen(version, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = temp1.communicate()

Then try to print the error.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement