我正在尝试通过 shell 运行另一个脚本,该脚本使用一组修改后的环境变量。
def cgi_call(script, environ):
pSCRIPT = subprocess.Popen(script, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, env=environ, shell=True)
pc = pSCRIPT.communicate()
status = "200 OK"
headers = [('Content-Type',"text/html")]
if pc[1] != '':
raise RuntimeError, pc[1]
else:
rval = str(pc[0])
return status, headers, rval
运行上面的代码后,我收到以下错误:
File "server/httpd.py", line 76, in DynamicServer
status, headers, rval = handler(environ)
File "server/httpd.py", line 43, in handler
status, headers, rval = cgi_call(srvpath+"../www/public_html"+environ["PATH_INFO"]+'index.py',environ)
File "server/httpd.py", line 21, in cgi_call
stdin=subprocess.PIPE, env=environ, shell=True)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
<type 'exceptions.TypeError'> execve() arg 3 contains a non-string value
传递环境变量时出现错误......我也尝试将它们作为字符串传递 - 它出错并说它需要一个映射对象。然而,实际上,传递的环境是一个映射对象......
问题是什么?
附加信息:我在 Ubuntu 12.04.1 上运行 Python 2.7