Modifying the interpreter's environment

Eric Bouck (ebouck@dsdbqvarsa.er.usgs.gov)
Wed, 14 Sep 1994 18:32:08 GMT

I need to set certain environment variables before making system and
popen calls. After reading the manual and FAQ, it's not clear to me
how this is accomplished. For the system calls, I realize it
wouldn't be terribly difficult to write a function that forks and
execve's, but I can't figure a way to make popen work this way.
Therefore, I think I still need to modify the environment of the
running python script? Can someone tell me how to do this?

Here's what I found in the manual:

- data of module posix: environ
A dictionary representing the string environment at the time the
interpreter was started. (Modifying this dictionary does not
affect the string environment of the interpreter.) For example,
`posix.environ['HOME']' is the pathname of your home directory,
equivalent to `getenv("HOME")' in C.

- function of module posix: system (COMMAND)
Execute the command (a string) in a subshell. This is implemented
by calling the Standard C function `system()', and has the same
limitations. Changes to `posix.environ', `sys.stdin' etc. are not
reflected in the environment of the executed command. The return
value is the exit status of the process as returned by Standard C
`system()'.

Eric