[GRASS5] G_done_msg(), stderr, and fileno()
Paul Kelly
paul-grass at stjohnspoint.co.uk
Mon Oct 24 07:23:08 EDT 2005
Hello Hamish
On Tue, 25 Oct 2005, Hamish wrote:
> Hi,
>
> G_done_msg() does some figuring on where to send the output:
> if (isatty(1))
> out = stdout;
> else if (isatty(2))
> out = stderr;
>
> for one thing, shouldn't that use fileno(stdout) instead of "1", and
> for another shouldn't it try to send to stderr first? always?
I think it should. Shouldn't even bother checking.
> G_message(), G_warning(), and G_fatal_error() all send exclusively to
> stderr, with the bell getting a isatty(fileno(stderr)) test.
>
>
> I've written a script which calls a module which uses G_done_msg().
> I'd like to pipe the stdout to a file, but currently the output of
> G_done_msg() is polluting matters.
Yes exactly. We had a discussion a while ago about r.proj printing a
message to say when it was finished or something and the suggestion was to
use G_done_msg(...) instead of fprintf(stderr, ...). I looked at the
source of G_done_msg() and thought that would be a bad idea so didn't
change anything. Meant to bring it up on the list but didn't get round to
it.
There must be a reason for the current logic in G_done_msg() though.
but in general, I feel the "output to stderr to stdout?" issue has been quite
confused in GRASS for a long time until we decided that anything that was
part of the results/analysis output of the module should go to stdout,
while informative user messages should go to stderr.
So probably most of what's in G_done_msg() should be stripped out and
simplified, IMHO.
Paul
More information about the grass-dev
mailing list