[GRASS-user] Using grass.run_commmand
Glynn Clements
glynn at gclements.plus.com
Sat May 21 09:53:48 EDT 2011
Luisa Peña wrote:
> is there any difference, when it comes to processing, between run_command
> and read_command?
run_command() executes the command and waits for it to terminate; it
doesn't redirect any of the standard streams.
read_command() executes the command with stdout redirected to a pipe,
and reads everything written to it. Once the command terminates, it
returns the data written to stdout as a string.
> and from read_command can I retrieve the error also?
None of the existing *_command functions redirect stderr. You can do
so with e.g.:
def read2_command(*args, **kwargs):
kwargs['stdout'] = grass.PIPE
kwargs['stderr'] = grass.PIPE
ps = grass.start_command(*args, **kwargs)
return ps.communicate()
This behaves like read_command() except that it returns a tuple of
(stdout,stderr) rather than just stdout.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list