[GRASS-dev] r.mapcal and python

Glynn Clements glynn at gclements.plus.com
Tue Nov 11 09:31:49 EST 2008


Massimiliano Cannata wrote:

> >>> Ciao Roberto,
> >>> try with this solution:
> >>>
> >>> output='yourmap'
> >>> map1='yourmap1'
> >>> map2='yourmap2'
> >>> cmdargs2=["%s=if(%s>%s,10000,0)"%(output,map1,map2)]
> >>> os.spawnvp(os.P_WAIT,"r.mapcalc", ["r.mapcalc"] + cmdargs2)
> >>>       
> >> Thank you, Maxi! It works perfectly well. I think I'll use this solution 
> >> rather than the grass.py library for 'r.mapcalc'.
> >>     
> >
> > Don't use the os.spawn* functions; they have been superseded by
> > subprocess.Popen() and subprocess.call().
> >
> >   
> Yes, replace spawn* with popen or call. It is the right direction.
> 
> P.s.: Only call can handle the P_WAIT mode?

subprocess.call() waits for the process to terminate, and returns its
exit code. It is defined as:

	def call(*popenargs, **kwargs):
	    return Popen(*popenargs, **kwargs).wait()

[plus a documentation string, which has been omitted above for
brevity.]

Examples of how to obtain equivalent behaviour to the os.* functions
are given in:

http://docs.python.org/library/subprocess.html#replacing-older-functions-with-the-subprocess-module

The only common case which the subprocess module doesn't replace is
the os.exec* functions.

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


More information about the grass-dev mailing list