[GRASSLIST:225] RE: running grass commands from CGI script

Matt Doggett mdoggett at coas.oregonstate.edu
Tue May 27 13:16:47 EDT 2003


Some more information...

* I am using grass5.0.2 and have tried both the new r.mapcalc and the
original r.mapcalc (4.3 version) with the same results.
* My CGI headers are formulated correctly prior to running the grass
script. Therefore, any STDOUT output would simply appear as text in my
browser.
* r.mapcalc prints a progression status to STDERR as the command runs.
i.e. 1%...2%...3%...etc.  (I find it interesting that it goes to STDERR
not STDOUT.) Also, it must be sending special cursor control characters
to the terminal (like backspaces or beginning of line) since it
continuously prints this % completion in the same place (hmmm, special
control-characters have been known to cause problems in some
environments).
* While these output go to STDERR, they do NOT show up the the Apache
error_log
* If I do NOT redirect STDERR to either a file or /dev/null, apache will
timeout on the CGI execution.


My conclusion...
* I can't say for sure whether there is anything *wrong* with either
Grass or Apache configuration--it just appears to me a mis-handling of
the behavior that r.mapcalc exhibits. It looks to be tied up in the
output that r.mapcalc sends to STDERR that reports the progress of the
r.mapcalc command.

My solution...
* If running CGI scripts that call the r.mapcalc command, redirect
STDERR to either a file or /dev/null. This is not a big deal as the
progression indicator (which seems to be the culprit) isn't very useful
in the CGI environment anyway.

My question...
* Is there a way to disable this status reporting of r.mapcalc command?

Hopefully this thread may help anyone attempting to do this in the
future.

-Matt

> -----Original Message-----
> From: owner-GRASSLIST at baylor.edu [mailto:owner-GRASSLIST at baylor.edu]
On
> Behalf Of Glynn Clements
> Sent: Friday, May 23, 2003 3:57 PM
> To: mdoggett at coas.oregonstate.edu
> Cc: GRASSLIST at baylor.edu
> Subject: [GRASSLIST:161] RE: running grass commands from CGI script
> 
> 
> Matt Doggett wrote:
> 
> > Upon further investigation, I discovered that if I redirect STDERR
and
> > STDOUT when I call r.mapcalc, this problem goes away (e.g.
`r.mapcalc
> > newgrid=A*B*C >somefile 2>&1`).
> >
> >   Maybe someone can shed some light as to what r.mapcalc is doing to
> > STDOUT and/or STDERR that might be causing problems with apache?
> 
> [What follows assumes that you're using GRASS 5.0.0 or later, which
> has a completely re-written r.mapcalc; the r.mapcalc in 4.3 and early
> 5.0 betas is substantially different.]
> 
> r.mapcalc writes error messages to stderr, but this shouldn't
> interfere with Apache; it's not uncommon for CGI scripts (or the
> programs they call) to write to stderr; any such output should end up
> in Apache's error log.
> 
> AFAICT, r.mapcalc itself shouldn't write anything to stdout; however,
> I can't entirely rule out the possibility that some lower-level
> function might write to stdout.
> 
> In the CGI script, are you generating the CGI header (Content-Type
> etc) early on, or are you leaving it until after r.mapcalc has been
> run? If a program writes to stdout before you've written the header,
> Apache will try to parse it as a CGI header, with unpredictable
> results.
> 
> --
> Glynn Clements <glynn.clements at virgin.net>




More information about the grass-user mailing list