Running exec on htmldoc would successfully execute the shell commands, but return this error:
child process exited abnormally
This would ruin my ns_returnfile since output was sent to the browser before the 200 header.
I discovered htmldoc returns 1 on success to stdout which is returned by catch and exec. Just catch the error and do nothing with it.
#
# Download the pdf
#
set file_name_pdf [ns_tmpnam]
append file_name_pdf ".pdf"
if {[catch {exec echo \ $html\ | /usr/share/htmldoc/htmldoc --webpage --quiet -f $file_name_pdf -} errmsg]} {
#Do nothing with the error and we're good.
}
ns_returnfile 200 application/pdf $file_name_pdf
return filter_return
Oh, and concerning the strangeness with
echo \[space]$html\[space]
This is the only way to simulate shell quotes with exec. Curly braces and \" do not seem to work. Remember that $html must be escaped - "[{ etc!
More info on exec: http://wiki.tcl.tk/1039
Hope this helps someone.