
Just what does "failure" mean?
Thanks to the folks who answered my question on open failure; I've
sent messages to some, and the email "system" has rejected my attempts
to reply to others. But I have a further question ....
In examining their replies, I determined that my main problem is
an inability to comprehend just what tcl means by "failure". In
trying to track this down, I documented a number of cases in which
[catch {exec foo}] returned 1 when foo returned 0. I've boiled it
down to the following curious case:
% cat foo.c
#include <stdio.h>
main() {
fprintf(stderr,"\n");
exit(0);
}
This program clearly exits normally; sh, ksh, csh and perl all agree
on this. But wish claims that foo fails:
% wish
% catch {exec ./foo} val
1
% puts \"$val\"
""
It appears that tcl considers a program to have failed if: 1) it returns
a nonzero exit status; 2) it writes *anything* to stderr; 3) possibly
other conditions that I haven't yet diagnosed.
Is this true? Is it documented? Is it reliable and portable? What
(if anything) goes in the 3) slot?
The problem with this, of course, is that Unix libraries are full of
programs that write informative messages to stderr, but if the problems
can be fixed or somehow handled, they still succeed and exit normally
(i.e., with a 0 status). Some demented programs (e.g., stty) even write
their normal output to stderr on some Unix systems. When called from a
wish script, they are treated as having failed, despite a 0 exit status.
It appears that the only solution to this is to write a wrapper that
execs the program, and eats the stderr output so that tcl doesn't see
it. Is this the correct interpretation of the situation? Is there
a more direct solution here that doesn't involve an extra process whose
sole function is to suppress (or redirect) stderr output?
(Note that I'm not criticising tcl's approach; I'm just trying to
understand it. I've had a lot of problems with wish scripts harassing
the poor users with error dialogs boxes that they don't stand a chance
of understanding; when I look at them, I don't understand either why
wish is harassing them about non-errors. To make it work right, I
must reach some minimal understanding of what tcl considers an "error",
and I frankly don't understand the Book's explanation, as is proven by
the fact that my wish scripts don't behave as I expect.)
--
The most important part of any research publication is the paragraph
near the end which begins with "Further research is needed ...".