How Do I Set Environment Variables ?

Cliff Crawford cjc26 at nospam.cornell.edu
Fri May 26 20:20:53 EDT 2000


* Shengquan Liang <sliang at florida-lnx.cc.gatech.edu> menulis:
| 
| I wrote the following code:
| 
|     	import os
| 	os.system("ORACLE_HOME=/opt/app/ora/")
| 	os.system("export ORACLE_HOME")
| 	....
| 
| I executed the script under my user account but
| when i checked my enviroment variables with "env"
| there is no ORACLE_ENV added.

That's because os.system spawns a new process (with a copy of the
original environment of the parent process) each time it's called.  You
want to use os.environ instead:

    os.environ["ORACLE_HOME"]="/opt/app/ora/"

This changes the environment for all future os.system calls.


| Another question is that, when the script is up
| on a web server, it's executed on behalf of
| 'nobody', will the enviroment variables be changed
| after running the script?

No; once the process dies, the changed environment dies with it.


-- 
cliff crawford    -><-    http://www.people.cornell.edu/pages/cjc26/
                          Synaesthesia now!            icq 68165166



More information about the Python-list mailing list