[GRASS-dev] Using grass.message in Python: Why does G_message() print to stderr and not stdout?

Markus Metz markus.metz.giswork at gmail.com
Sun Sep 9 07:23:01 PDT 2018


On Sun, Sep 9, 2018 at 3:47 PM Markus Neteler <neteler at osgeo.org> wrote:
>
> Hi,
>
> Why does G_message() print to stderr and not stdout?
> https://trac.osgeo.org/grass/browser/grass/trunk/lib/gis/error.c#L84

Messages, warnings and errors are not output. Consider g.region -g, r.info
-g, r.univar -g or any module that produces an output file with default
output=- meaning stdout. You don't want any messages in the output if the
output is to be automatically parsed later on.

Markus M

>
> This is a big problem when working with grass.run_command() and
> friends since Python tends to buffer error messages (or occasionally
> eats them). I have no reference why Python does so but there a myriad
> of posts from people complaining about it.
>
> Why an issue? I am currently debugging a long Python script on a
> remote system, all docker based, and errors do not really show up. But
> especially the grass.message()  output is not there so that I can not
> easily add debug output. So, the latter I would like to change.
> To now add simple print() statements (on stdout) in a GRASS GIS Python
> script is a bit against the idea of grass.message()...
> Can grass.message() please (optionally) print on stdout?
>
> Likely I am missing something - suggestions are welcome.
>
> thanks
> Markus
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20180909/b253f42f/attachment.html>


More information about the grass-dev mailing list