如何解决使用来自 python
我需要使用另一个 python 脚本将变量文本通过管道传输到 bash 脚本中。它不会产生错误,但根本不会触发 bash 脚本。
#!/usr/bin/python
import cgi;
import cgitb;cgitb.enable()
import subprocess
import os
import sys
# Create instance of FieldStorage
form = cgi.FieldStorage()
lang = ''
# Get data from fields
lang = form.getvalue('lang')
sText = form.getvalue('text')
def sendBashCommand(bCommand):
p = subprocess.Popen(bCommand.split())
p.communicate() # wait until command is done
devnull = open(os.devnull,'w')
if lang != 'DE' and lang != 'EN':
lang = 'DE'
print "Content-Type: text/html\n\n"
print ""
print "<html><body>"
print "<center><font size=-2>"
print "Spoken text: #" + sText + "# Language: " + lang
print "<br><br>\r\n"
sys.stdout.flush()
sendStr = ''
if sText != '' and lang == 'DE':
sendStr = "echo " + sText + " |speakpi.DE"
sendBashCommand(sendStr)
print sendStr + "<br><br>"
elif sprechText != '' and lang == 'EN':
sendStr = "echo " + sText + " |speakpi"
sendBashCommand(sendStr)
print sendStr + "<br><br>"
else:
sendStr = ''
print "Parameter missing<br><br>"
print "done!"
print "</font><br>"
print "</center>"
print "</body></html>"
我用
触发cgihttp://myIP/cgi-bin/speak.cgi?text=hello&lang=DE
浏览器输出符合预期。
Spoken text: #hello# Language: DE
hello | /usr/local/sbin/speakpi.DE echo hello | /usr/local/sbin/speakpi.DE
done!
我的猜测是我搞砸了 popen 部分 - 但如果要纠正它,我会迷失方向。 建议?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。