[Tutor] Environment Variables On Windows

Mark Kels mark.kels at gmail.com
Sun Dec 26 20:57:58 CET 2004


> Morning Mark,
> 
> Happy New Year, Merry Christmas, and a jolly Winter Solstice Season!
> 
> Whenever you're talking about how to do something in Windows it REALLY
> helps when you include WHICH windows you're working with.
> 
> I believe the following will allow you to manipulate windows
> environmental variables.  If anyone sees I'm wrong I know they'll speak
> up.  The "set" command when run in a command window without parameters
> lists your current environmental variables.  You can also use it as:
> c:\> set hello=Hi there Mark
> which will set the variable "HELLO" to "Hi there Mark".
> c:\> echo %HELLO% or
> c:\> echo %hello%
> will now print "Hi there Mark" without the quotes.
> 
> Note that quoting, case sensitivity, and white spaces can all react
> differently under windows than they do in Python.
> 
> If you need to set an environmental variable to a value every time you
> start windows then you can either store the above set command (no spaces
> around that "=" remember) in the autoexec.bat file or on Windows 2000,
> XP and (I believe) NT you can right click on the desktop icon "My
> Computer" and select "Properties".  Now you're looking for the
> "Advanced" tab and the environmental variables button in Windows 2000.
> I THINK it's under the "System Performance" tab and advanced button in
> XP and you'll have to dig in NT.  I'm not sure you can do this here
> under the win 95/98/ME family.   Sorry, right now the only windows
> product I'm running at home is 2000.
> 
> You can also set Windows environmental variables from within your python
> script of course.
> 
> FYI being a coward myself before I go changing my setup I like to
> document things.  Say running "set > Environment-Before.txt" in a nice
> safe directory.  This will output your current setup so if things get
> weird you can at least bring things back to you starting point.
> 
> Have a good one,
> 
> John Purser
> 
Thanks allot !!
But I don't understand how to use the environment variables in the
script itself...
I tried to do this:

import os
import cgitb; cgitb.enable()
print "Content-type: text/html\n\n"
print "Hi there, ",os.system("echo %USERNAME%")

But I don't get anything in the browser (500 error - Internal Server
Error) and when I run the script in IDLE I get:

Hi there,  0

I guess its not the way to print them, but it's the only way I came up with.
And I got another question:
In my server program I have "User CGI Environment Variables" list that
should have pares of  Name:Value in it...
Whats that? (I guess its the same in all server programs).

Thanks!

BTW, I'm running Windows XP and Abyss Web Server on my PC.
-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon


More information about the Tutor mailing list