Created
November 8, 2012 15:33
-
-
Save yangjuven/4039501 to your computer and use it in GitHub Desktop.
test for python cgi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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