0

I have a program that spits out pure bytes of a PNG image. I've been trying to attach this output with a bash cgi script that spits out a simple html web page with the output of the program attached as the data.

I.e.

#!/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

This works fine if I pipe the request through TCP to an intermediate server program but that has the disadvantage that I have to have a separate server program running to link the cgi scripts to the programs.

Thank you for help!

[EDIT]

Ahh, I've figured it out. It was as simple as the following:

echo "HTTP/1.1 200 Ok"
...
java -jar program.jar @parm
2
  • 1
    StackOverFlow allows you to answer your own question. This is a good idea, since it could help someone in the future. Suggest you move the answer from your earlier edit into the answer box. Commented Mar 6, 2014 at 0:39
  • I tried that the first time round but there was was a 10 hour delay before you could answer your own post. I've fixed it now. Thanks. Commented Mar 7, 2014 at 14:16

1 Answer 1

1

Ahh, I've figured it out. It was as simple as the following:

echo "HTTP/1.1 200 Ok"
...
java -jar program.jar @parm

(the program outputs the data (bytes of the image) into std out. When I wrapped inside bash's "echo" it seems it wrapped the bytes into a string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.