[GRASS-user] Calling GRASS scripts from GRASS C modules

Markus Neteler neteler at osgeo.org
Wed Mar 23 04:23:09 EDT 2011


On Wed, Mar 23, 2011 at 5:14 AM, Glynn Clements
<glynn at gclements.plus.com> wrote:
>
> Markus Neteler wrote:
>
>> > 7.0 has G_popen_{read,write}, which do most of the work for you, but
>> > these haven't been back-ported to 6.x yet.
>>
>> I have compared the two lib/gis/popen.c files. Is backport as "easy" as
>> adding the GRASS 7 functions in 6 to also keep the old G_popen() and
>> G_pclose() for backward compatibility?
>
> Yes.
>
> But the existing G_popen() and G_pclose() functions should either be
> removed or replaced with:
>
>        FILE *G_popen(const char *cmd, const char *mode)
>        {
>            return popen(cmd, mode);
>        }
>
>        int G_pclose(FILE *ptr)
>        {
>            return pclose(ptr);
>        }
>
> There's no reason to (attempt to) provide our own implementations of
> these functions, particularly when the Windows version is completely
> broken.
>
> Note that G_popen() has already been removed from 6.5, with the code
> changed to use popen() instead. This still suffers from the usual
> issues with trying to reliably construct a shell command, but it
> avoids the G_popen()-specific bugs.

So I will replace the existing popen.c file in 6.4.svn with the code above.
It goes into 6.4.2 then.

> In 7.0, all references to popen() have been removed, and the only use
> of system() is in D_close_driver(), to execute a shell command
> specified by the GRASS_NOTIFY environment variable.

ok.

Markus


More information about the grass-user mailing list