[Tutor] Environment Variables On Windows

Alan Gauld alan.gauld at freenet.co.uk
Mon Dec 27 12:27:58 CET 2004


> 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%")

If you ignore the environment variable bit, does
it work with a hard coded name?

If so then try using the function os.getenv() to
fetch the variable, better than os.system anyway!
os.system return an error code not the string,
so you'd wind up printing either 0 or some error number!

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

But this looks like a more fundamental error.
Try to get it working without the env  var first.

BTW Since you are using Python have you looked
at the python cgi tutoprial using the cgi module?
THe O'REilly one ois fine if you want to understand
what cgi module does under the covers, but using
cgi is much easier...

HTH

Alan G.



More information about the Tutor mailing list