[plt-scheme] Mac OS X 10.1.5, Apache 1.3.26, MZScheme 201 and CGI/Shell Scripting

From: Paul Graunke (ptg at ccs.neu.edu)
Date: Fri Oct 11 15:41:41 EDT 2002

The shell script your CGI program is calling refers to $HOME, which may
very well not be set or be set to something else in the context of apache.
I'm assuming that sort and awk are in the $PATH, but that would be the next
thing I would check.

Paul

At Fri, 11 Oct 2002 15:16:08 -0400, Scott Rogers wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> 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 ); }



Posted on the users mailing list.