[GRASS5] Small glitch in d.measure
glynn.clements at virgin.net
Thu Sep 16 05:12:24 EDT 2004
Michael Barton wrote:
> I just encountered a new, minor glitch in d.measure.
> >From GIS Manager menus, execute d.measure starts the tcltk gui for the
> command. However, the output is pretty meaningless while the command is
> running. Here is an example:
That's because d.measure calls G_clear_screen(), which calls
system("clear"). Those are the "clear screen" sequence for xterm:
$ infocmp xterm | fgrep clear
clear=\E[H\E[2J, cnorm=\E[?25h, cr=^M,
> AFTER you quit, you get a nice screen of information that looks like this
> This information (except for the final totals) needs to be shown during the
> measurement session. This was the case in recent version of d.measure.
This is a buffering issue. By default, stdout is block-buffered if it
is associated with a pipe, which is the case when it is run from the
However, if you use "d.measure -s", the G_clear_screen() calls are
suppressed, and the information is written to stderr rather than
stdout. stderr is always unbuffered.
AFACIT, it isn't possible to merge stderr and stdout so that both are
sent back to Tcl. You can redirect stderr to a file or to an existing
descriptor; however, the pipe to which stdout is connected is created
by the open call, so you can't use it in the argument to open.
I suggest making two changes to d.measure:
1. Only call G_clear_screen() if stdout is a tty; although, this
change should probably go into G_clear_screen() itself.
2. Either explicitly make stdout line-buffered, or call fflush() after
writing each block of data.
> Probably related to this, you now cannot get d.measure to open its tcltk
> dialog from the command line. It only seems to operate in xterm mode. Seems
> like some switch needs to be set differently.
d.measure is another one of those programs which has an argc check:
if (argc > 1 && G_parser(argc,argv))
This is because all of the parameters are optional; typical usage is
to run d.measure without arguments. You can use "d.measure --ui" to
force the dialog to be displayed.
Glynn Clements <glynn.clements at virgin.net>
More information about the grass-dev