0

我在Windows 7上測試與Oracle Data Integrator 11g的一些接口。 所有接口在運行時都使用LKM MSSQL到Oracle(BCP/SQLLDR),但出現錯誤在「通過Jython調用SQLLDR」命令上。一些invesetigation後,我發現,問題的根源是下面的代碼行:ODI - 在Windows Shell上通過Jython調用SQLLDR

exitCode = os.system(sqlldr + " control=" + tempSessionFilePrefix + ".ctl log=" + tempSessionFilePrefix + ".log " + "userid=" + "<% out.print(odiRef.getInfo("DEST_USER_NAME")); %>" + "/" + "<% out.print(odiRef.getInfo("DEST_PASS")); %>" + tnsnameOption + " > " + tempSessionFilePrefix +".out"); 

應該在窗體上的Windows Shell中運行一個字符串:

sqlldr control=control_file.ctl log=log_file.log userid=ODI_STAGE/ODI_STAGE > shell_output.out 

我沒有運行字符串直接在命令提示符下生成,並且沒有任何問題。

所以打了一下代碼後,我無法讓os.system工作,所以我用subprocess.call替換了它。我也有去除串的最後部分,它試圖保存在命令提示符(> shell_output.out)的輸出中,以使整個事情的工作:

exitCode = subprocess.call([sqlldr, "control=" + tempSessionFilePrefix + ".ctl", "log=" + tempSessionFilePrefix + ".log", "userid=" + "<% out.print(odiRef.getInfo("DEST_USER_NAME")); %>" + "/" + "<% out.print(odiRef.getInfo("DEST_PASS")); %>" + tnsnameOption], shell=True); 

這一個工程進展順利。

關於shell輸出,我懷疑問題是字符串部分以'>'charcater開頭,它被解析爲SQLLDR的參數的一部分,而不是提示的命令。 現在,雖然我可以沒有它,但我想問問是否有人知道任何簡單的解決方法來獲取shell輸出。

回答

0

好吧,我終於能夠得到shell輸出。 我編輯用下面的「呼叫SQLLDR通過Jython的」命令:

from __future__ import with_statement 
import subprocess 

... 

with open(tempSessionFilePrefix + ".out", "w") as fout: 
exitCode = subprocess.call([sqlldr, "control=" + tempSessionFilePrefix + ".ctl", "log=" + tempSessionFilePrefix + ".log", "userid=" + "ODI_STAGE" + "/" + "<@=snpRef.getInfo("DEST_PASS") @>" + tnsnameOption], stdout=fout, shell=True); 

現在一切工作按預期。