[GRASS-dev] Python script problem

Glynn Clements glynn at gclements.plus.com
Thu Oct 25 17:11:51 EDT 2007


monik1982\@libero\.it wrote:

> Hello everybody,
> I'm new to python and I'm trying to build up a script...
> 
> When I run the script the only commands that are executed are 
> 
>     cmdargs1= ["elevation=%s" %dtm]
>     cmdargs2=["slope=slope1", "format=percent", "--overwrite"]   
>     os.execvp("r.slope.aspect", ["r.slope.aspect"] + cmdargs1 + cmdargs2)
> 
> 
> The other commands are ignored...What can be the issue?

os.execvp() doesn't return (unless it fails); it executes the
specified command *in place of* the script which calls it.

If you want to run a command without terminating the script, use
subprocess.Popen as suggested by Michael. For more details, see §17.1
of the Python library reference:

	http://docs.python.org/lib/module-subprocess.html

In most scripts, the only place where os.execvp() should be used is
for invoking g.parser.

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




More information about the grass-dev mailing list