简体   繁体   English

subprocess.popen使cgi脚本卡住

[英]subprocess.popen making the cgi script stuck

When opening the page with following code the page keeps loading forever.. 当使用以下代码打开页面时,页面将永远加载。

import cgitb
import subprocess,shlex
cgitb.enable()
print "Content-type:text/html\r\n\r\n"
print 'Hello'
CMD = '/usr/bin/python -u /path/to/file/filename.py -c %s -r'
cmd = CMD % 'somearg'
proc = subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE)
output, status = proc.communicate()
print '<pre>%s</pre>' % output

and works only after i take out the subprocess.Popen() part. 并且仅在我取出subprocess.Popen()部分后才能工作。 Strange thing is this code used to work before and I don't remember making any change recently that may have messed with it. 奇怪的是,这段代码以前曾经工作过,我不记得最近做过任何可能使其混乱的更改。 Also the subprocess.Popen() part works perfectly from python shell, so the code is correct. 而且subprocess.Popen()部分在python shell中也可以正常工作,因此代码是正确的。 I am stuck in finding what is making the page load forever. 我一直在寻找使页面永久加载的原因。 I have searched for solutions on web but cant find one. 我在网上搜索了解决方案,但找不到。 Looking for suggestions to solve this. 寻找解决此问题的建议。 Thanks 谢谢

CMD缺少“ \\ n”。

CMD = '/usr/bin/python -u /path/to/file/filename.py -c %s -r\n'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM