[GRASS-dev] obtain the progress percentage of a command run from
python
Glynn Clements
glynn at gclements.plus.com
Thu Dec 1 23:39:43 EST 2011
Glynn Clements wrote:
> import grass.script as grass
> env = os.environ.copy()
> env['GRASS_MESSAGE_FORMAT'] = 'gui'
> p = grass.start_command(..., stderr = grass.PIPE, env = env)
> # read from p.stderr
> p.wait()
>
> If you need to capture both stdout and stderr, you need to use
> threads, select, or non-blocking I/O to consume data from both streams
> as it is generated in order to avoid deadlock.
Or: redirect both stdout and stderr to the same pipe (and hope that
the normal output doesn't include anything which will be mistaken for
progress/error/etc messages):
p = grass.start_command(..., stdout = grass.PIPE, stderr = grass.STDOUT, env = env)
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list