[plt-scheme] Mac OS X 10.1.5, Apache 1.3.26, MZScheme 201 and CGI/Shell Scripting
All,
I am running the following configuration:
Mac OS X 10.1.5
Apache 1.3.26
MZScheme 201
And I am working on a CGI application. Here is the problem, when I
execute the script from the command line, I get the expected result.
When I execute it as a CGI from Apache, get #<eof> returned. I am able
to run mzscheme CGI scripts, but this on causes me a problem.
When the shell script is executed from the command line like so:
./test-process.scm
The following is appears on stdout:
Content-type: text/html
/Users/scottr/projects/discuss/bin/gltid.sh<br/>
/Users/scottr/projects/discuss/data/topics.current<br/>
264
However, when I execute it as a CGI through Apache, the following is
returned to the browser:
/Users/scottr/projects/discuss/bin/gltid.sh
/Users/scottr/projects/discuss/data/topics.current
EOF!
;;; Scheme Script
#!/bin/sh
":";exec /usr/local/bin/mzscheme -r $0 "$@"
(require (lib "cgi.ss" "net"))
(require (lib "process.ss"))
(output-http-headers)
(define get-last-topic-id
(lambda ()
(let ((p "/Users/scottr/projects/discuss/bin/gltid.sh")
(a "/Users/scottr/projects/discuss/data/topics.current"))
(cond ((not (file-exists? p))
(display p)
(display ": does not exist.<br/>"))
((not (file-exists? a))
(display a)
(display ": does not exist.<br/>"))
( #t
(display p)(display "<br/>\n")
(display a)(display "<br/>\n")
(let ((results (process* p a)))
(let ((topic-id (read-line (car results))))
(close-input-port (car results))
(close-output-port (cadr results))
(close-input-port (cadddr results))
(if (eof-object? topic-id)
"EOF!"
topic-id))))))))
(display (get-last-topic-id))
(display "\n")
;;; The shell script it's calling is as follows:
sort -n -t , -k 1 $1 | awk -F, -f $HOME/projects/discuss/bin/gltid.awk
;;; The awk script is as follows:
#
# Get Last Topic ID
#
BEGIN { FS = ","; }
{
id = $1;
}
END { print( id ); }