Bugs item #1100235, was opened at 2005-01-11 17:00
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1100235&group_id=5470
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: pacote (pacote)
Assigned to: Nobody/Anonymous (nobody)
Summary: Scripts started with CGIHTTPServer: missing cgi environment
Initial Comment:
With Python 2.4 only (2.3 works fine). Tested on
Windows 2000.
In run_cgi, sys.environ is updated with cgi variables
(QUERY_STRING, etc.)
but it seems that this environment is not passed to the
child process.
On Windows os.popen3 is used but something must have
changed in that function that is causing this regression.
The attached patch fixes this using the subprocess module.
It fixes also (I think) bug 1088039
("directories/scripts with spaces in their name").
Supports too Python installed in a directory with a
space (e.g. "Program Files").
Patch note: the subprocess test (have_subprocess) is
kind of awkward: is there a better way to do this?
Diff follows, complete script attached.
-----
--- C:\apps\Python24\Lib\CGIHTTPServer-old.py Mon Aug
30 09:38:16 2004
+++ C:\apps\Python24\Lib\CGIHTTPServer.py Tue Jan 10
19:45:09 2005
@@ -234,18 +234,16 @@
elif self.have_popen2 or self.have_popen3:
# Windows -- use popen2 or popen3 to
create a subprocess
+ import subprocess
import shutil
- if self.have_popen3:
- popenx = os.popen3
- else:
- popenx = os.popen2
- cmdline = scriptfile
+
+ cmdline = '"%s"' % scriptfile
if self.is_python(scriptfile):
interp = sys.executable
if interp.lower().endswith("w.exe"):
# On Windows, use python.exe, not
pythonw.exe
interp = interp[:-5] + interp[-4:]
- cmdline = "%s -u %s" % (interp, cmdline)
+ cmdline = '"%s" -u %s' % (interp, cmdline)
if '=' not in query and '"' not in query:
cmdline = '%s "%s"' % (cmdline, query)
self.log_message("command: %s", cmdline)
@@ -253,11 +251,11 @@
nbytes = int(length)
except (TypeError, ValueError):
nbytes = 0
- files = popenx(cmdline, 'b')
- fi = files[0]
- fo = files[1]
- if self.have_popen3:
- fe = files[2]
+
+ p = subprocess.Popen(cmdline,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+
stderr=subprocess.PIPE, env=os.environ)
+ (fi, fo, fe) = (p.stdin, p.stdout, p.stderr)
+
if self.command.lower() == "post" and
nbytes > 0:
data = self.rfile.read(nbytes)
fi.write(data)
@@ -267,16 +265,16 @@
break
fi.close()
shutil.copyfileobj(fo, self.wfile)
- if self.have_popen3:
- errors = fe.read()
- fe.close()
- if errors:
- self.log_error('%s', errors)
+ errors = fe.read()
+ fe.close()
+ if errors:
+ self.log_error('%s', errors)
sts = fo.close()
if sts:
self.log_error("CGI script exit status
%#x", sts)
else:
self.log_message("CGI script exited OK")
+ del p
else:
# Other O.S. -- execute script in this process
----------------------------------------------------------------------
>Comment By: Martin v. L�wis (loewis)
Date: 2005-01-29 14:34
Message:
Logged In: YES
user_id=21627
As juneaftn says, this was caused by #1110478, and is fixed in
os.py 1.85
test_os.py 1.29
NEWS 1.1235
os.py 1.83.2.1
NEWS 1.1193.2.17
----------------------------------------------------------------------
Comment By: June Kim (juneaftn)
Date: 2005-01-27 08:24
Message:
Logged In: YES
user_id=116941
Please have a look at #1110478. The cause is in os.py.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1100235&group_id=5470
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com