This is more of a tcl question than aolserver but its coming up in my server so I'll start here. Is there a way to make exec not do translations on the returned data? Here's my exact situation. I have a proc to handle php files by spawning the standalone "php" program (this it low-volume so I'm not overly worried about how inefficient this setup is). This is my proc:

proc runPhp {file} {
  set body [ns_conn content]
  array set cgienv {
     SERVER_SOFTWARE AOLserver/4.0
  set cgienv(CONTENT_LENGTH) [string length $body]
  set cgienv(CONTENT_TYPE) [ns_set get [ns_conn headers] Content-Type]
  set cgienv(REQUEST_METHOD) [ns_conn method]
  set cgienv(REMOTE_ADDR) [ns_conn peeraddr]
  set cgienv(QUERY_STRING) [ns_conn query]
  set cgienv(SCRIPT_NAME) [ns_conn url]
  set cgienv(SCRIPT_FILENAME) $file
  foreach {hl v} [ns_set array [ns_conn headers]] {
    set cgienv(HTTP_[string map {- _} [string toupper $hl]]) $v

  set sli [interp create]
  interp eval $sli array set env [list [array get cgienv]]
  interp eval $sli [list set body $body]
  interp eval $sli [list set file $file]
  # binary workaround
  interp eval $sli {set pf [open "|php $file" r+]}
  interp eval $sli {fconfigure $pf -translation binary}
  interp eval $sli {puts $pf $body}
  interp eval $sli {flush $pf}
  set result [interp eval $sli {read $pf}]
  interp eval $sli {close $pf}
  # set result [interp eval $sli exec php $file << \$body]
  interp delete $sli
  set lines [split $result "\n"]
  if {[string match "Status:*" [lindex $lines 0]]} {
    regsub {^Status:\s*} [lindex $lines 0] "" status
    set lines [lrange $lines 1 end]
  } else {
    set status "200 OK"
  ns_write "HTTP/1.0 $status \n"
  ns_write [join $lines "\n"]

using [open "|php" r+] works ok, but it makes me nervous about getting stuck in a deadlock, where the php program is waiting for eof but never getting it since that won't happen until it closes the filehandle at which time it is gone. [exec php << $body] is much cleaner and works, except for the things that want to return binary content like images, and those get mangled by tcl's default line-ending handling.

So - is there any way to make exec use binary translation (i.e., no translation) in what it returns?


AOLserver -

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to