Skip to content

Instantly share code, notes, and snippets.

@yangjuven
Created November 8, 2012 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangjuven/4039501 to your computer and use it in GitHub Desktop.
Save yangjuven/4039501 to your computer and use it in GitHub Desktop.
test for python cgi.
#!/usr/bin/env python
# -*- coding: utf8 -*-
import os
import sys
import subprocess
environ = {
"QUERY_STRING": "name=juven",
"REQUEST_METHOD": "GET",
"REQUEST_URI": "/cgi/hello.py?name=juven",
"SCRIPT_NAME": "/cgi/hello.py",
"SCRIPT_URI": "http://x.com/cgi/hello.py",
"SCRIPT_URL": "/cgi/hello.py",
"SERVER_NAME": "x.com",
"SERVER_PORT": "80",
"SERVER_PROTOCOL": "HTTP/1.1",
}
root = os.path.abspath(__file__)[:-len("/test.py")]
p = subprocess.Popen("python %s/hello.py" % root, \
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=environ)
retval = p.wait()
if retval != 0:
print p.stderr.read()
else:
print p.stdout.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment