[GRASS-dev] 'g.gui wxpython' won't work in wingrass as wxgui is a shell script

Glynn Clements glynn at gclements.plus.com
Thu Feb 28 06:51:47 EST 2008


Martin Landa wrote:

> Hi,
> 
> 2008/2/21, Glynn Clements <glynn at gclements.plus.com>:
> 
> >  Moritz Lennert wrote:
> >  > as wxgui is a shell script, g.gui wxpython (which does:
> >  >
> >  >  else if (strcmp(type->answer, "wxpython") == 0) {
> >  >         sprintf (progname, "%s/etc/wxpython/scripts/wxgui", G_gisbase());
> >  >         if (rc_file->answer) {
> >  >             G_spawn(progname, "wxgui", rc_file->answer, NULL);
> >  > )
> >  >
> >  > will not work.
> 
> since gis.m and d.m are also shell scripts, g.gui tcltk|oldtcktk will
> not work too(?)

The batch file may work, but I would suggest invoking gm.tcl directly,
similar to the above.

The gis.m script ends up executing either:

	exec "$GRASS_WISH" "$GISBASE/etc/gm/gm.tcl" -name gm_tcl &
or:
	exec "$GRASS_WISH" "$GISBASE/etc/gm/gm.tcl" -name gm_tcl "$GIS_OPT_DMRC" sh &

So the corresponding C code should be roughly:

	sprintf(progname, "%s/etc/gm/gm.tcl", G_gisbase());
        if (rc_file->answer) {
	    G_spawn(getenv("GRASS_WISH"), "gis.m", progname, "-name", "gm_tcl", rc_file->answer, NULL);
	}
	else {
	    G_spawn(getenv("GRASS_WISH"), "gis.m", progname, "-name", "gm_tcl", NULL);
	}

Similarly for d.m.

BTW, I have no idea what that trailing "sh" is doing there. I think
that it's just getting ignored, anyhow.

> There is one problem, when you run `g.gui wxpython`, the program is
> waiting for thread termination. So you cannot use xterm when wxGUI is
> running. I am not sure how to fix it since I am not so familiar with
> G_spawn*.

G_spawn() behaves like system() in that it waits for termination.

You could use G_spawn_ex() with the SF_BACKGROUND flag (although we're
still waiting for a Windows implementation of G_spawn_ex()), or you
could fork() before calling G_spawn() (but fork() doesn't exist on
windows).

So far as a Windows implementation of G_spawn_ex() is concerned, a
partial implementation using spawnvp() or spawnvpe() should be
relatively straightforward, and better than nothing.

That wouldn't support redirection, current directory, or signal
handling (I don't think that signal handling can be implemented on
Windows in any case). But implementing SF_BACKGROUND is
straightforward (don't use P_WAIT), and implementing environment
bindings isn't particularly problematic (the existing environment is
in the global variable "_environ").

AFAICT, a version based upon CreateProcess() would also allow the
redirection and current directory flags to be implemented.

FWIW, the primary function which needs to be re-implemented is
do_spawn(), in lib/gis/spawn.c.

Off the top of my head, the following seems about right:

static int do_spawn(const char *command)
{
	char **env;
	int status;
#if 0
	/* these also need implementing, eventually */
	do_redirects(redirects, num_redirects);
	env = do_bindings(_environ, bindings, num_bindings);
#else
	env = _environ;
#endif

	status = spawnvpe(background ? _P_NOWAIT : _P_WAIT, command, (char **) args, env);

	if (!background && status < 0)
		G_warning(_("Unable to execute command"));

	return status;
}

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


More information about the grass-dev mailing list