[GRASS5] Re: [bug #3709] (grass) d.m - commands output pollutes the Grass terminal

Glynn Clements glynn at gclements.plus.com
Sat Oct 22 08:01:29 EDT 2005


Michael Barton wrote:

> Thanks for looking at this. Run_panel is indeed based directly on your run
> procedure from a year or so back (part of the execute, run, spawn, and term
> procedures you did to resolve problems in the pull-down menu system).
> 
> Given what you say...
> 
> 1) Should run_panel be eval exec -- $cmd >@ /dev/null  ?
> 2) Should this be the case for the run procedure too?

Ideally it would use the internal log window, but redirecting to
/dev/null is probably the next best thing.

Note that if the terminal has the TOSTOP flag set (i.e. "stty tostop"),
a background process which tries to write to the terminal
will be suspended, which is undesirable.

In any case, stderr has to be redirected somewhere, as exec generates
an error if anything is written to stderr and it hasn't been
redirected.

> I struggled over gui.tcl for many hours last weekend. I understand what it
> is doing pretty much, but it is considerably more complicated than needed in
> this case and I was unable to extract or create the code to redirect all
> output to the window at the bottom of the GIS Manager.

Try the following (untested):

	proc cmd_output {fh} {
		global outtext
		while {![eof $fh]} {
			set str [gets $fh]
			append str "\n"
			if { [fblocked $fh] } { set str [read $fh] }
			while {[set idx [string first "\b" $str]] != -1} {
				set last [expr $idx - 1]
				set str1 [string range $str 1 $last]
				set first [expr $idx + 1]
				set str [string range $str $first end]
				set pos [$outtext index "end - 1 chars"]
				$outtext delete $pos
				$outtext insert end $str1
			}
			$outtext insert end $str
			$outtext yview end
			update idletasks
		}
		close $fh
	}

	proc run_panel {cmd} {
		global outtext
		set cmd [concat | $cmd 2>@ stdout]
		if { [catch {open $cmd r} fh] } {
			error $fh
		}
		$outtext insert end "$cmd\n"
		$outtext yview end
		cmd_output $fh
	}

This differs from the mechanism used in gui.tcl, as run_panel needs to
wait until the command has completed before it returns.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list