[GRASS-user] Announcing new command line interface of `grass` program in trunk

Rainer M Krug Rainer at krugs.de
Thu Jun 4 00:53:15 PDT 2015

Vaclav Petras <wenzeslaus at gmail.com> writes:

> Hi all,
> I'm happy to announce new command line interface of the `grass` program [1,
> 2] available in trunk.

This sounds very exciting - and will make life much easier. Thanks a

It might be to early to ask, but are there any penalties is speed when
using this construct compared with the "traditional" way?

> Certainly you already know that you can start GRASS GIS session in the
> specified Location and Mapset in the following way:
> grass71 .../grassdata/location/mapset/
> The new interface adds `--exec` flag for specifying a command which will be
> executed inside that GRASS session:
> grass71 .../grassdata/location/mapset/ --exec r.univar map=elevation

Am I right in assuming, that the --exec effectively splits the command
into the "setup part" (mapset) before and the "command part" after and
whatever follows will be executed?

What happens when one specifies a shell command - I assume it will it also be

I guess that if this is working, the next step would be to introduce the
single command version so that one does not have to specify the mapset
each time. E.g:

| grass71 --setmapset .../grassdata/test1/PERMANENT/
| grass71 --exec r.external input=basins.tiff output=basins
| grass71 --exec r.external input=elevation.tiff output=elevation
| grass71 --unsetmapset

| grass71 --setmapset .../grassdata/test1/PERMANENT/
| grass71 --exec r.external input=basins.tiff output=basins
| grass71 --exec r.external input=elevation.tiff output=elevation
| grass71 --unsetmapset

and finally introduce a mapper around this (similar to Rscript ore
littler) so that one could say

| grass71exec setmapset .../grassdata/test1/PERMANENT/
| grass71exec r.external input=basins.tiff output=basins
| grass71exec r.external input=elevation.tiff output=elevation
| grass71exec unsetmapset

and could use grass71exec as a shebang - that would be the ultimate

Thanks a lot,


> This starts GRASS session, executes whatever command is specified after
> `--exec` flag and then ends showing the (text) output of the module as if
> the module would be executed manually in the GRASS session. And example
> showing this in combination with r.external to get the data into the Mapset
> is in the documentation [3].
> This interface is meant to remove the need for lengthy manual setup of
> environmental variables followed by execution of GRASS modules in the
> mock-up GRASS session [4]. The idea is to use correct GRASS session
> maintained by `grass` program which means that any GRASS-related code must
> be passed to the `grass` program as opposed to direct execution in the
> former case.
> The interface can run any module or custom script with or without
> parameters. GUI tools including g.gui [5] can be called as well which opens
> new possibilities for application developers.
> The interface is the first implementation and currently is fully
> operational only on Linux and similar systems but it benefits from a lot of
> stable code which was already in place. Try it out and feel free to comment
> here, on grass-dev or in the related ticket [6]. There is definitively many
> potential improvements and it would be great to know what the community
> demands.
> Vaclav
> [1] https://trac.osgeo.org/grass/changeset/65252
> [2] https://trac.osgeo.org/grass/changeset/65294
> [3]
> http://grass.osgeo.org/grass71/manuals/grass7.html#exec-interface-example
> [4]
> http://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly
> [5] https://trac.osgeo.org/grass/changeset/65306
> [6] https://trac.osgeo.org/grass/ticket/2579
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user

Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 494 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20150604/62396dd2/attachment.pgp>

More information about the grass-user mailing list