[GRASS-dev] r.mapcal and python

Glynn Clements glynn at gclements.plus.com
Tue Nov 11 09:23:17 EST 2008


Roberto Antolí­n wrote:

> >>> cmdargs2=["%s=if(%s>%s,10000,0)"%(output,map1,map2)]
> >>> os.spawnvp(os.P_WAIT,"r.mapcalc", ["r.mapcalc"] + cmdargs2)
> > 
> > Don't use the os.spawn* functions; they have been superseded by
> > subprocess.Popen() and subprocess.call().
> 
> 
> After your (all) messages I searched for some information about 
> subprocess.* and saw that os.spawn* were replaced by them.
> 
> Thank you for pointing me this! It confirms my doubts. In fact, 
> subprocess.* are currently being used in grass.py library, aren't they? 
> Using subprocess.* will give some kind of homogeneity.

Yes, the various grass.*_command() functions are all implemented on
top of subprocess.Popen().

The grass module provides wrappers for subprocess.Popen() and
subprocess.call(). The only difference between these wrappers and the
versions in the subprocess module is that the GRASS versions set
shell=True on Windows (this is so that it will execute scripts as well
as binary executables).

The most basic process creation function is grass.start_command(),
which uses grass.make_command() to construct the argument list, then
passes it to grass.Popen(). All of the other functions are based upon
grass.start_command().

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


More information about the grass-dev mailing list