【发布时间】:2014-04-08 07:47:32
【问题描述】:
我有一个程序可以输出 PNG 图像的纯字节。我一直在尝试使用 bash cgi 脚本附加此输出,该脚本会吐出一个简单的 html 网页,并将程序的输出作为数据附加。
即
#!/bin/bash
parm=($QUERY_STRING) # capture the query string (from url)
output=$(java -jar Program.jar $parm) # capture the bytes of the PNG image
len=${#output} # figure out the size of the png image
# simple web page with png image
resp="HTTP/1.1 200 OK\r\nContent-Type: image/png\r\nConnection: close\r\nContent-Length: $len\r\n\r\n$output"
echo -en $resp # cgi teleport that hogwash out
如果我通过 TCP 将请求传送到中间服务器程序,这可以正常工作,但缺点是我必须运行单独的服务器程序才能将 cgi 脚本链接到程序。
感谢您的帮助!
[编辑]
啊,我想通了。就这么简单:
echo "HTTP/1.1 200 Ok"
...
java -jar program.jar @parm
【问题讨论】:
-
StackOverFlow 允许您回答自己的问题。这是一个好主意,因为它可以在将来帮助某人。建议您将之前编辑的答案移到答案框中。
-
我第一次尝试过,但在您回复自己的帖子之前有 10 小时的延迟。我现在已经修好了。谢谢。