[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 12:36:49 PDT 2018


On Sun, Sep 9, 2018 at 4:46 PM Markus Neteler <neteler at osgeo.org> wrote:
>
> On Sun, Sep 9, 2018 at 4:23 PM Markus Metz
> <markus.metz.giswork at gmail.com> wrote:
> > 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.
>
> OK, I see.
> So, for output like "Step X: processing ...:" I need to use print()?

this is going to stdout
>
> My preferred way would be grass.debug() because then I would later
> switch these message to level 1 in order to "hide" them. Yet, I think
> that they disappear...

if stderr disappears, they disappear

the question is, what happens with stderr in Python? Where is it? Is it
recoverable? See also your other post.
>
> I'd also like to see a way to print through the parser, i.e. a
> functionality similiar to "sh -x shellscript" which prints every step.
> Is that possible?

In Python you mean? Maybe one of the GRASS Python gurus can answer that
(not me).

Markus M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20180909/4c6ee568/attachment.html>


More information about the grass-dev mailing list