Well, here is an area where Tcl doesn't make it as easy as it could. The exit code of an
exec'ed program is available, but not in a straightforward manner.
When an error occurs in Tcl, it stores values in a couple of pre-defined global variables. One of those is
errorInfo, which gets a stack track of the Tcl commands executing at the time of the error. The other is
errorCode, which is "set to hold additional information about the error in a form that is easy to process with programs" -- at least according to the
tclvars reference page. The value of
errorCode is a list, whose elements depend on the type of error that occurred.
When a child process exits with a non-zero exit code, the value of
errorCode contains 3 elements: the string "CHILDSTATUS", the process ID of the child process, and the exit code. On the Tcl'ers Wiki (
the "exec" page,
has an excellent example from Kevin Kenny showing how you can handle all the permutations and combinations of child process termination.
Another possibility, if it's an option for you, is to use the
bgexec command from the
BLT extension. It has some
really nice features for dealing with external programs, including an extremely simple method of getting the program's exit code. You can find out more information at "bgexec,"
and "BLT,"
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting,
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax