0

Hi I am trying to check for java version by using below python code

os.environ["PATH"] = os.environ["PATH"] + os.pathsep + "C:\Program Files\Java\jdk1.8.0_20\bin"
os.system("java -version")

but it shows this error message

'java' is not recognized as an internal or external command, operable program or batch file.

2 Answers2

0

'\b' is a BACKSPACE character, not \ and b.

>>> "\b"
'\x08'
>>> print("\b")

To represent \ and b literally, you need to escape \, or use r'raw string literal':

>>> print("\\b")
\b
>>> print(r"\b")
\b
falsetru
  • 357,413
  • 63
  • 732
  • 636
0

I tried to print the PATH

os.system("echo %PATH%")

then I found some weird text like below

C:\Program Files\Java\jdk1.8.0_20in

\b in \bin is showing as backspace char in path

replace path with below works fine

C:\\Program Files\\Java\\jdk1.8.0_20\\bin