Issue1100235
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2005-01-11 16:00 by pacote, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Files | ||||
---|---|---|---|---|
File name | Uploaded | Description | Edit | |
CGIHTTPServer.py | pacote, 2005-01-11 16:00 | New version of CGIHTTPServer.py |
Messages (3) | |||
---|---|---|---|
msg23924 - (view) | Author: pacote (pacote) | Date: 2005-01-11 16:00 | |
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 |
|||
msg23925 - (view) | Author: June Kim (juneaftn) | Date: 2005-01-27 07:24 | |
Logged In: YES user_id=116941 Please have a look at #1110478. The cause is in os.py. |
|||
msg23926 - (view) | Author: Martin v. Löwis (loewis) * | Date: 2005-01-29 13:34 | |
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 |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:09 | admin | set | github: 41423 |
2005-01-11 16:00:05 | pacote | create |