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

Glynn Clements glynn.clements at virgin.net
Tue May 27 17:47:30 EDT 2003


Matt Doggett wrote:

> * 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.

OK.

> * r.mapcalc prints a progression status to STDERR as the command runs.
> i.e. 1%...2%...3%...etc.

r.mapcalc should display 2% increments, i.e. 0%...2%...4%...etc.

> (I find it interesting that it goes to STDERR
> not STDOUT.)

This is standard practice; output which is only intended for a human
operator (progress indication, prompts etc) is written to stderr, so
that it's still displayed on the terminal if stdout is redirected to a
file.

As r.mapcalc doesn't (intentionally) write to stderr, this isn't
applicable here. However, the progress output is generated by the
G_percent() function, which is used by many GRASS programs, some of
which may write to stderr data which might reasonably be redirected to
a file.

> 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

Backspace codes (ASCII code 8) are written to return the cursor to the
beginning of the line:

	fprintf (stderr,"%4d%%\b\b\b\b\b",x);

> (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?

No. Many (most?) commands which display a progress percentage either
only do so if a -v (verbose) switch is used, or allow it to be
disabled via a -q (quiet) switch. However, r.mapcalc doesn't have any
options or switches; the entire command line is treated as an
expression.

It should probably check whether stderr is a tty, and only display the
percentages if it is. It alread checks stdin (the "mapcalc>" prompt is
only displayed if stdin is a tty).

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-user mailing list