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

Glynn Clements glynn at gclements.plus.com
Wed Mar 23 00:48:56 EDT 2011


Monica Buescu 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?
> 
> In my case I'm using 6.4.1 from September 2010 (before the major changes in
> WxPython GUI) and I want to run it in Windows. So, am I able to use that?

If you don't need to communicate with the child process via a pipe,
you can use G_spawn() or G_spawn_ex(). These provide similar
functionality to system() but without the shell getting in the way
(using the shell creates problems if filenames or other arguments
contain spaces or other characters which are significant to the
shell).

If you need to communicate via a pipe, you can either use G_spawn_ex()
and manage the pipe yourself (see lib/db/dbmi_client/start.c for an
example), or use popen(). Don't use G_popen(); the Unix version is
practically the same as popen() anyhow, and the Windows version is
completely broken.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list