os.system('java') or os.system('java -jar ...')
returns
'java' is not recognized as an internal or external command, operable program or batch file.
However, when I call "java" from command line, it works perfectly fine. The directory with java.exe is in my path. os.system('C:\Windows\System32\java.exe') also does not work. Also, os.system('find') or os.system('ftp') also work, even though they are also exe's in System32.
Rob Volgman
2,1143 gold badges18 silver badges28 bronze badges
1 Answer 1
This is because python doesn't have the same paths as your regular command line. You might be having a problem with escape characters - try using forward slash instead of backslash, or using a raw string. os.system('C:/Windows/System32/java.exe')
answered Jul 25, 2012 at 20:22
Rob Volgman
2,1143 gold badges18 silver badges28 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
os.system('C:\\Windows\\System32\\java.exe')('C:\\Windows\\System32\\java.exe')andos.system('C:/Windows/System32/java.exe')etc. and they resulted in the same error. Interestingly, I tried adding the openjdk/jre directory to thePATHand apparently that worked. I still don't understand why the executable there should work when the system32 one doesn't.