ODIExperts.com

The blog for Oracle Data Integrator ( ODI )

Jython OS bug in Windows 7

There are lots of users who are using Windows 7 on their personal machine and being a latest product  there is not much support from the codes of Jython causing some issues . Stating that i recently came across a small issue and i would like to share with you all and provide the solution.

In ODI , we can call Windows and Unix based command using Jython  and it uses the  OS.getOSType() to identify  the Operating system . If the Operating systems are Windows based it identifies them as ‘ NT’  and executes cmd  and if they are Unix or Linux based it identified them as ‘ POSIX ‘  and execute shell scripts.

In ODI , this os.getOSType() is stored in the  python file – oracledilibscriptingLibjavaos.py.

_osTypeMap = (        ( "nt", r"(nt)|(Windows NT)|(Windows NT 4.0)|(WindowsNT)|"                r"(Windows 2000)|(Windows XP)|(Windows CE)|(Windows 2003)"),         ( "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        )

While i was trying to call the startcmd.bat  in windows 7 i was getting an error like this

OSError: (0, ‘Failed to execute command ([‘sh’, ‘-c’, )

java.io.IOException: Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified’)

which is getostype()  considers Windows 7  as ‘POSIX’ and so its searching for shell  scripts and throwing me the above error

The resolution is simple ,  just add Windows 7 to the list into the file – oracledilibscriptingLibjavaos.py  ( Line No 302 )

_osTypeMap = (        ( "nt", r"(nt)|(Windows NT)|(Windows NT 4.0)|(WindowsNT)|"                r"(Windows 2000)|(Windows XP)|(Windows CE)|(Windows 2003)|(Windows 7)"),         ( "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        )

Looking to know your os type – try this code  in jython.bat or jython.sh

import os
print os._getOsType()

There are some time when we would like to execute a single process irrespective of Operating system either Unix or Windows.  Although we can call the OS command , the other way to do that is to writing command based on the environment . We can use OS Type to get the environment.

import os
if os._getOsType() == 'nt':   
      print 'Windows environment'
else:   
      print 'Unix environment '

Say if we want to write a copy command depending on environment  so the above command be re-written as

import os
if os._getOsType() == 'nt':   
      os.command(r “ copy /r source_path dest_path”)
else:   
      os.command (r “ cp -f source_path dest_path” )

 

Look in odiexperts for more tips and solutions.

4 Comments

  1. The acquaintance has advised to come on the given blog and is obvious knowingly.

  2. The easiest solution is uncomment “python.os” property in registry file(s) and set it to python.os=nt

    oracleproduct11.1.1Oracle_ODI_1oraclediclientjdevextensionsoracle.odi.navigatorscriptingregistry

    oracleproduct11.1.1Oracle_ODI_1oracledi.sdklibregistry

  3. Kshitiz,

    I’m using the LKM MSSQL to Oracle (BCP/SQLLDR) and I’m getting the “java.io.IOException: Cannot run program “sh”: CreateProcess error=2, The system cannot find the file specified’” error when ODI tries to call the BCP.

    This Interface is executed in a Windows 2008 server, so I included the “Windows Server 2008 R2” in the “javaos.py”, as you said on your post, and when I test the “print os._getOsType()” via “jython.bat” it returns “nt” correctly. But when I try to execute the Interface again, it returns the same error.

    Do you have any idea about what’s going on?

    Thanks,

    Jose Mauricio

Leave a Reply

Required fields are marked *.