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

I am wondering if anyone ran into this problem. Whenever I run any jython program in Eclipse, I got the following error at the beginning of the output:

"Failed to get the environment, the environment will be empty: (0, 'Failed to execute the command ([\' sh \ ', \' - c \ ', \' env \ ']): java.io.IOException: failed run the program "sh": Crea teProcess error = 2, the system cannot find the file indicated ')

Firstly, my environment:

Windows 2008

JDK 1.6.0u10

jython 2.2.1

I did a little work and realized that this message is being created in the javaos.getenv () function. Whenever I call the javaos.getenv () function, it throws the following error:

C: \ jython2.2.1> java -jar jython.jar

  

import javaos

         

javaos.getenv( "user.name" )

  

, : (0, ' command ([\ 'sh \',\'- c \',\'env \']): java.io.IOException: "sh": Crea teProcess error = 2, ')

, Windows-, Unix. /?

.

+3
5

os

( , 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
+4

. , , : http://www.koders.com/python/fid4B7C33153C1427D2CE19CE361EA9519D1652F802.aspx?s=self

, , jython , os - posix. , "Windows 2008". , . Windows Server 2008? , , _getOsType , , . , jython Eclipse. , , . .

+2

Windows 7. Jython script wsadmin Websphere. . n- javaos.py script: os sys.registry.getProperty( "python.os" ) \java.lang.System.getProperty( "os.name" ) "Windows Vista". , , Windows Vista javaos.py, .

+2

, Windows Vista Jython 2.5.1, Eclipse/PyDev. javaos.py, "Windows Vista" OR getOsType; . ( Tracker PyDev SourceForge.)

:

I installed the full version of Jython and it did not help. I also tried editing the registry file in the Jython tree. It didn’t 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 some 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
0
source

I used this hack from the 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
0
source

Source: https://habr.com/ru/post/1698845/


All Articles