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

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.