[GRASS-dev] New wiki page summarising GRASS APIs
Glynn Clements
glynn at gclements.plus.com
Tue Feb 3 07:35:12 PST 2015
Moritz Lennert wrote:
> This is what the warning before the system call examples says:
>
> "Warning: In many cases, system calls such as these demand that you
> really know what you are doing. If you want to program in Python, you
> are encouraged to rather use the existing Python APIs explained below
> instead of such system calls."
>
> And then it goes on with:
>
> "These system calls are easy to handle when no output is expected from
> the GRASS module. When output needs to be collected then the programming
> task already becomes a little harder unless you know what you are doing.
> Equally, they can be tricky when introducing variable arguments and
> special characters. It is for this reason that the Python GRASS
> libraries where developed that are explained in the next section."
>
> I hope this is explicit enough.
I still think that the C version should either be removed or use e.g.
posix_spawn() or G_spawn*() instead of system() (note: the Windows
spawn*() functions aren't safe; they merely concatenate their
arguments with spaces inbetween, which is no better than system()).
The perl version should be changed to use the list form of system()
rather than the string form, e.g.
@args = ("r.watershed", "elevation=elevation", "threshold=10000", "stream=raster_streams");
system(@args);
Under no circumstances should a command be passed as a string, even in
examples. Especially in examples. Telling people not to use that
approach won't work, particularly when it's the only approach
demonstrated.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list