Jython - javaos.getenv() gives “Failed to get environment, environ will be empty”

与世无争的帅哥 提交于 2019-12-05 19:07:46

Try to uncomment and change the os setting in the 'registry' file

(it is in the same directory as your jython.jar / i hope)

# python.os determines operating-specific features, similar to and overriding the
# Java property "os.name".
# Some generic values are also supported: 'nt', 'ce' and 'posix'.
# Uncomment the following line for the most generic OS behavior available.
#python.os=None
python.os=nt
# try nt or dos

Interesting. Well, I seem to have found the relevant code here: http://www.koders.com/python/fid4B7C33153C1427D2CE19CE361EA9519D1652F802.aspx?s=self

If you look towards the bottom, it seems when setting the environment command jython thinks your os is posix. You say you're using "Windows 2008". I'm not sure what that is. Do you mean Windows Server 2008? If so, it's quite new and if you look at the _getOsType function in the same module, it looks like it might be too new for that module. You may need to upgrade to the most recent version of jython or Eclipse. But it's quite possible they haven't yet released a version that supports this OS. If that's the case, you may need to just report the bug to them.

I'm running on Windows 7. I'm running Jython as a script in the Websphere wsadmin tool. I encountered this same error. I cut-n-pasted these lines from javaos.py into my script: os or sys.registry.getProperty( "python.os" ) or \ java.lang.System.getProperty( "os.name" ) and it returned "Windows Vista". So I performed the same surgery as suggested above, ie., add Windows Vista to javaos.py and that solved my problem.

deeeptext

I ran into the same error, using Windows Vista, and Jython 2.5.1, under Eclipse/PyDev By editing javaos.py, to include "Windows Vista" in the OR statement in getOsType,; I fixed the error. (I've filed a bug with the fix under the PyDev Tracker at SourceForge.)

Details:

I installed the full version of Jython, and that did not help. I also tried editing the "registry" file in the Jython tree. That did not help either.

Then I looked at the files in:

C:\eclipse-platform-3.5-win32\eclipse\plugins\org.python.pydev.jython_1.4.8.2881\Lib

to find "javaos.py" and added a bit of code to read:

def _getOsType( os=None ):
   os = os or sys.registry.getProperty( "python.os" ) or \
               java.lang.System.getProperty( "os.name" )

_osTypeMap = (
    ( "nt", r"(nt)|(Windows NT)|(Windows NT 4.0)|(WindowsNT)|"
            r"(Windows 2000)|(Windows XP)|(Windows CE)|(Windows Vista)" ),
    ( "dos", r"(dos)|(Windows 95)|(Windows 98)|(Windows ME)" ),
    ( "mac", r"(mac)|(MacOS.*)|(Darwin)" ),
    ( "None", r"(None)" ),
    ( "posix", r"(.*)" ), # default - posix seems to vary mast widely
    )
for osType, pattern in _osTypeMap:
    if re.match( pattern, os ):
        break
return osType

I've used this hack from Dave Brands blog: http://dbrand666.wordpress.com/2010/04/08/fix1/

try:
    import javaos
    if javaos._osType == 'posix' and \
            java.lang.System.getProperty('os.name').startswith('Windows'):
        sys.registry.setProperty('python.os', 'nt')
        reload(javaos)
except:
    pass
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!