Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why cannot os.environ be passed to child process ?

Status
Not open for further replies.

IPOz

Programmer
Jul 11, 2001
109
CN
A python CGI program can run on linux but not on
windows. By looking at CGIHTTPServer.py, we found out the reason: on windows, the
parent cannot pass os.environ to child demonstrated
as below:


main.py

import os, sys, shutil

env = {}

env["AAA"] = "111"
os.environ.update(env)

print os.environ["AAA"] # ok, updated successful

files = os.popen3(sys.argv[1], "b")

fi, fo, fe = files[0], files[1], files[2]

shutil.copyfileobj(fo, sys.stdout)

errors = fe.read()

fe.close()

if errors: print errors

sts = fo.close()

if sts:

print "exit %#x" % sts

else:

print "exit ok"


test.py

import os, sys

if os.environ.has_key["AAA"]:

print "ok, got AAA"

else:

print "failure"


c:\ test.py
it will print failure

main.py is adopted from CGIHTTPServer.py ?!

ipo_z@cmmail.com
garbage in,garbage out
 
I would imagine it's a limitation of the operating system since it can be done quite nicely in Unix.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top