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

Glynn Clements glynn at gclements.plus.com
Wed Nov 29 15:45:11 EST 2006


Hamish wrote:

> catch{open "|cmd"} doesn't return the exit code of "|cmd", while
> catch {exec "cmd"} does. The only thing that comes to mind is that in
> the "open" case catch is catching the channel_id of the open{} function,
> not the result of "|cmd":
> 
> open(n) "returns a channel identifier"
>   http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/open.n.html
> 
> so the catch currently tests if a channel identifier could be opened ?

Errors in child processes are normally indicated by the corresponding
"close" throwing an exception.

Most errors (returning a non-zero exit code or writing to stderr)
can't be detected at the time that "open" is called, as the error
hasn't happened at that point.

An error from the execve() call (e.g. a missing executable) could be
caught at that point, but I don't think that would apply to errors
loading shared libraries (which is the responsibility of the program
rather than the OS kernel).

Even so, Tcl may defer reporting such errors to the corresponding
"close" for simplicity (you only need to catch exceptions in one place
rather than two). The open(n) manpage says:

	If the command (or one of the commands) executed in the
	command pipeline returns an error (according to the definition
	in exec), a Tcl error is generated when close is called on the
	channel (similar to the close command.)

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




More information about the grass-dev mailing list