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

Markus Neteler neteler at osgeo.org
Sun Sep 9 13:47:16 PDT 2018


On Sun, Sep 9, 2018 at 10:13 PM Vaclav Petras <wenzeslaus at gmail.com> wrote:
> On Sun, Sep 9, 2018 at 3:37 PM Markus Metz <markus.metz.giswork at gmail.com> wrote:
> > On Sun, Sep 9, 2018 at 4:46 PM Markus Neteler <neteler at osgeo.org> wrote:
> >
> > >
> > > 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?

> It is not clear to me either what you are asking for. Do you want every Python line? Python can do that with module `trace` (python -m trace --trace).
> Here is an example (just for testing purposes, using the --tmp-location and --exec):
>
> grass --tmp-location XY --exec python -m trace --trace `grass --tmp-location XY --exec which r.mask` -r

Good to know. Yet that's not what I meant - it also shows all the subcalls etc.

> That gives little too much information, so perhaps:
>
> FILE="`./bin.x86_64-pc-linux-gnu/grass77 --tmp-location XY --exec which r.mask`"
> grass --tmp-location XY --exec python -m trace --trace $FILE -r | grep `basename $FILE`
>
> Or do you want GRASS parser to print every module being executed?

Yes, just the sequence of commands along with the parameter/flags
used. Like "shell history" style. This would help for a quick
orientation in long Python scripts with functions etc.

Markus


More information about the grass-dev mailing list