[GRASS-dev] Re: [GRASS-CVS] michael: grass6/gui/tcltk/gis.m mapcanvas.tcl, 1.52, 1.53

Hamish hamish_nospam at yahoo.com
Tue Nov 28 20:58:36 EST 2006


> grass intevation.de wrote on 11/28/2006 12:14 AM:
> > Author: michael
> >
> > Update of /grassrepository/grass6/gui/tcltk/gis.m
> > In directory doto:/tmp/cvs-serv16736
> >
> > Modified Files:
> > 	mapcanvas.tcl 
> > Log Message:
> > Added error trap for g.region failing at GUI startup. Now it exits
> > GUI with a message about g.region failing.
> >
> > Index: mapcanvas.tcl
> > ===================================================================
> > RCS file: /grassrepository/grass6/gui/tcltk/gis.m/mapcanvas.tcl,v


Markus wrote:
> Excellent, Michael.
> Now we no longer see the "parts()" error in gis.m. I have backported
> it to 6.2-CVS for 6.2.1.


This does not work for me unfortunately. (both wish 8.3 and 8.4)

I moved /usr/lib/libgdal.so out of the way to simulate breakage, then:
G63> g.region -p
g.region: error while loading shared libraries: libgdal1.3.1.so.1: cannot open shared object file: No such file or directory
G63> echo $?
127


I changed:

- if {![catch {open [concat "|g.region" "-ug" $args] r} input]} {
+ set regcmd [concat "|g.region" "-ug" $args]
+ set retval [catch {open $regcmd r} input]
+ if {! $retval } {


But catch returns 0 and the return stream ($input) is not filled
with the stderr message (it's empty).

To get it to fail nicely I need to add some more checking:


if {! $retval } {

  set havedata 0
  while {[gets $input line] >= 0} {
    if { ! $havdata } {
      set havedata 1
    }
    regexp -nocase {^([a-z]+)=(.*)$} $line trash key value
    set parts($key) $value
  }

  if { ! $havedata } {
    # eof check probably redundant
    if { [eof $input] } {
      puts "Startup error: check 'g.region -p'"
      exit 1
    }
  }
  catch {close $input}

  ...
}



I can get it to pass through the "missing libgdal.so" message with:
 set regcmd [list exec "g.region" "-ug" $args]
 set retval [catch $regcmd result]
 if { $retval } {
   puts "Startup error:\n $result"
   exit 1
 }
 puts "result is: $result"


but when I restore libgdal it then fails with:
Failed to run command:
 ERROR: region <> not found      (that's from g.region main.c region=)


????

Hamish




More information about the grass-dev mailing list