Issue2569

classification
Title: jython launcher fails on Windows if JAVA_HOME is set
Type: behaviour Severity: normal
Components: Core Versions:
Milestone: Jython 2.7.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jamesmudd, jeff.allen
Priority: Keywords:

Created on 2017-03-13.22:39:33 by jamesmudd, last changed 2017-03-14.19:57:59 by jeff.allen.

Messages
msg11223 (view) Author: James Mudd (jamesmudd) Date: 2017-03-13.22:39:32
Trying to execute the jython using the exe or python launch script on Windows fails if JAVA_HOME environment variable is set

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\user\Desktop\dist\bin>jython.exe
Jython 2.7.1rc1 (, Mar 13 2017, 08:51:49)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
Type "help", "copyright", "credits" or "license" for more information.
>>> 
KeyboardInterrupt -------- Works Ok

C:\Users\user\Desktop\dist\bin>set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_121"

C:\Users\user\Desktop\dist\bin>jython.exe
Traceback (most recent call last):
  File "jython.py", line 444, in <module>
    if __name__ == "__main__":
  File "jython.py", line 435, in main
    print command
  File "subprocess.py", line 168, in call
  File "subprocess.py", line 390, in __init__
  File "subprocess.py", line 640, in _execute_child
WindowsError: [Error 5] Access is denied
Failed to execute script jython --------- Fails

Running as admin doesn't help. I think the problem is when JAVA_HOME is set then cmd used to invoke java is the full path C:\Program Files\Java\jdk1.8.0_121\bin\java and python doesn't seem to have permission to launch this. However when JAVA_HOME is not set the cmd used is just java and it relies on java being on the path, it seems python can launch this?

Any ideas for a fix? Or others give it a try and see if it fails for you?
msg11229 (view) Author: Jeff Allen (jeff.allen) Date: 2017-03-14.19:57:58
I can certainly reproduce, but it works if I remove the quotes.

> set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_121"

> jython --print
"\"C:\Program Files\Java\jdk1.8.0_121\"\bin\java" -Xmx512m -Xss1024k -classpath C:\jython\2.7.1rc1\jython.jar;. -Dpython.home=C:\jython\2.7.1rc1 -Dpython.executable=C:\jython\2.7.1rc1\bin\jython.exe -Dpython.launcher.uname=windows -Dpython.launcher.tty=true org.python.util.jython

Notice the questionable use of quotes? Tidy them up and it runs.

> "C:\Program Files\Java\jdk1.8.0_121\bin\java" -Xmx512m -Xss1024k -classpath C:\jython\2.7.1rc1\jython.jar;. -Dpython.home=C:\jython\2.7.1rc1 -Dpython.executable=C:\jython\2.7.1rc1\bin\jython.exe -Dpython.launcher.uname=windows -Dpython.launcher.tty=true org.python.util.jython
Jython 2.7.1rc1 (default:8a87a1e6d515, Feb 28 2017, 04:33:36)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

And similarly, if you define the variable without them:

> set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121

> jython
Jython 2.7.1rc1 (default:8a87a1e6d515, Feb 28 2017, 04:33:36)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
Type "help", "copyright", "credits" or "license" for more information.
>>>

I know it's quite common to quote paths in environment variables or scripts, especially if there are spaces invoilved, but this time it works against you. If we wanted to be resilient to this kind of thing (#2346), maybe we'd strip them in the launcher before composing the path?
History
Date User Action Args
2017-03-14 19:57:59jeff.allensetnosy: + jeff.allen
messages: + msg11229
2017-03-13 22:39:33jamesmuddcreate