[GRASS-user] Using grass.run_commmand

Glynn Clements glynn at gclements.plus.com
Thu May 19 12:08:28 EDT 2011


Luisa Peña wrote:

> I'm using grass.run_command and I have one question: besides setting flags,
> parameters can I also get error and output from that function like
> p=grass.run_command("r.out.xyz", parameters=X, flags="f...", stdout=output,
> stderr=error)

Use read_command or pipe_command.

read_command returns the command's output (stdout) as a string.

pipe_command returns the Popen object; read from its .stdout member. 
Call the .wait() method when you're done with it. For details of Popen
objects, see:

http://docs.python.org/library/subprocess.html#popen-objects

The most general function is start_command, upon which all of the
*_command functions (except for exec_command) are built. Again, this
function returns the Popen object.

Refer to the source code ($GISBASE/etc/python/grass/script/core.py)
for more details. Most of those functions are only a few lines long.

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


More information about the grass-user mailing list