Help setting CGI Environment Variables

Ari David Greenberg arigreen at stanford.edu
Sun May 27 02:57:07 EDT 2001


Thanks for your help. This approach DOES let my code run correctly, in
that it displays TEST_VAR as an environment variable. However, this
doesn't really set the environment variable for this process.

According to the python documentation, "such changes to the environment
affect subprocesses started with os.system(),popen() or fork() and
execv().

Is there any way to change the environment variables to affect the current
process? If not, what would be the easiest way of starting a subprocess to
take advantage of the new environment vars. Thanks

-Ari


On Sun, 27 May 2001, Roman Suzi wrote:

> On Sat, 26 May 2001, Ari David Greenberg wrote:
>
> >I am trying to write a CGI script that must modify some CGI environment
> >variables. How should I do this? I tried the following:
> >
> >#!/usr/pubsw/bin/python
> >import sys, os
> >os.putenv("TEST_VAR", "/abc")
> >
> >for name, value in os.environ.items():
> >	print "%s\t= %s" % (name, value)
>
> #!/usr/bin/python
> import sys, os
> os.environ["TEST_VAR"] = "/abc"
> for name, value in os.environ.items():
>         print "%s\t= %s" % (name, value)
>
> gives you this result.
>
> *
>
> However, I'd liked to do it this way:
>
> exec """
> TEST_VAR1 = "/abc"
> TEST_VAR2 = "/abc"
> """ in os.environ.data
>
> for name, value in os.environ.items():
>         print "%s\t= %s" % (name, value)
>
>
> - but it remains unclear if this is legal. (os.environ is
> an object).
>
> >
> >
> >I ran this program from the command prompt, and it printed all my
> >environment variables however it did not print TEST_VAR. I am concerned
> >that I am not setting TEST_VAR properly. I thought os.putenv(<name>,
> ><value>) was the way to do it, but I'm having difficulties.
> >
> >Any help greatly appreciated. Please email me.
> >
> >-Ari
> >
> >
>
> Sincerely yours, Roman Suzi
> --
> _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
> _/ Sunday, May 27, 2001 _/ Powered by Linux RedHat 6.2 _/
> _/ "Hard work must have killed someone!" _/
>
>
>




More information about the Python-list mailing list