-1

hi I'm trying to run sqlldr from python script, before that I'm trying to set ORACLE_HOME from python as below

subprocess.call(["export","ORACLE_HOME=/home/user1/oracle/client"], shell=True)

when I run the above python script, it displays all environment variables. When I search for ORACLE_HOME in that it never displays the one which I set (/home/user1/oracle/client) instead it displays someother path which is incorrect.

How can I set the ORACLE_HOME in unix from python script?

Shashi
  • 199
  • 1
  • 6
  • 19
  • Won't that export to the subprocess shell and not to your current shell? – Anshul Goyal Oct 11 '13 at 06:40
  • so how can I set ORACLE_HOME and execute some commands from python? I would like to call sqlldr once ORACLE_HOME is set. how can I make use of subprocess shell to execute multiple commands? – Shashi Oct 11 '13 at 06:42
  • Your question is a duplicate of this one http://stackoverflow.com/questions/8365394/set-environment-variable-in-python-script – Anshul Goyal Oct 11 '13 at 06:43
  • I have answered for setting the varibale, check if that works. You should probably ask another question describing your usage and what you have attempted for making use of subprocess shell to execute multiple commands. – Anshul Goyal Oct 11 '13 at 06:51

1 Answers1

1

You can set up the ORACLE_HOME variable like following

import os
import subprocess

os.environ['ORACLE_HOME'] = "/home/user1/oracle/client"
subprocess.call("printenv") #prints whole environment, see the ORACLE_HOME there
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186