Glynn Clements glynn at gclements.plus.com
Sat Nov 25 13:56:14 EST 2006

Jachym Cepicky wrote:

> I would need to catch progress of r.los in one python script. I used
> following approach
> os.putenv("GRASS_MESSAGE_FORMAT","gui")
> for line in os.popen("r.los in=elevation.dem out=tmp 2>&1").readlines():
>     print line
> It works well, but all the "lines" are printed out, just after r.los is
> finished, but not while it is processing the raster map.

The documentation for the readlines() method says:


    Read until EOF using readline() and return a list containing the
    lines thus read. If the optional sizehint argument is present,
    instead of reading up to EOF, whole lines totalling approximately
    sizehint bytes (possibly after rounding up to an internal buffer
    size) are read. Objects implementing a file-like interface may
    choose to ignore sizehint if it cannot be implemented, or cannot
    be implemented efficiently.

The "until EOF" means that it isn't going to return until the command
has completed.

> Could somebody help me, how to do it? Could you point me to tcl code,
> which must solve this problem too?

Looking at the Python docs, you probably want something like:

	f = os.popen("r.los in=elevation.dem out=tmp 2>&1")
	    for line in f:
	        print line

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list