0
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
asked Jul 25, 2012 at 20:03
3
  • 1
    Try os.system('C:\\Windows\\System32\\java.exe') Commented Jul 25, 2012 at 20:08
  • ikz - please learn about formatting your posts. They will be much more readable. Commented Jul 25, 2012 at 20:38
  • 1
    I tried os.system ('C:\\Windows\\System32\\java.exe') and os.system('C:/Windows/System32/java.exe') etc. and they resulted in the same error. Interestingly, I tried adding the openjdk/jre directory to the PATH and apparently that worked. I still don't understand why the executable there should work when the system32 one doesn't. Commented Jul 25, 2012 at 22:56

1 Answer 1

2

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.