Hi
I have following problem: I need to run external script which outputs image to standard output. To deliver it to client I use hunchentoot:send-headers call.
Following code works fine: (setf (hunchentoot:content-type*) "image/png") (setf (hunchentoot:header-out "Pragma") "no-cache") (let ((out (hunchentoot:send-headers))) (let ((process (sb-ext:run-program "generate-image" '() :output :stream :wait nil :error nil))) (let ((file (sb-ext:process-output process))) (loop with buf = (make-array 10240 :element-type '(unsigned-byte 8)) for pos = (read-sequence buf file) until (zerop pos) do (write-sequence buf out :end pos)))))
But when I want to use stream from "send-headers" as stream for standard output for external program then status line and headers received after image content. I use following code: (setf (hunchentoot:content-type*) "image/png") (setf (hunchentoot:header-out "Pragma") "no-cache") (let ((out (hunchentoot:send-headers))) (let ((process (sb-ext:run-program "generate-image" '() :output out :wait nil :error nil))) (sb-ext:process-wait process)))
So I have following question: is it possible to use stream received from "send-headers" as output stream for spawned process or not? If yes how correct code must look?
Thanks in advance
I need to run external script which outputs image to standard output.
http://cyrusharmon.org/projects?project=hunchentoot-cgi
Andrey
On Tue, Feb 1, 2011 at 8:00 AM, Alexey Martynov martynov.alexey@gmail.com wrote:
So I have following question: is it possible to use stream received from "send-headers" as output stream for spawned process or not?
I'd say this depends on how sb-ext:run-program works. If it can accept a Lisp stream to send its output to, you should be fine.
From http://www.sbcl.org/manual/Running-external-programs.html it
looks like what you're doing is correct. This doesn't work for you? Maybe SBCL expects another stream type?