[GRASS-dev] python and GRASS_MESSAGE_FORMAT
Daniel Calvelo
dca.gis at gmail.com
Sat Nov 25 21:02:38 EST 2006
Hi Jachym. This looks like a buffered vs. unbuffered stream problem.
Looking at lib/gis/percent.c, the output of (the G_percent calls of)
r.los should flush at every write so if you try to popen in unbuffered
mode, you should get what you need: try os.popen("your_cmd","r",0).
HTH, Daniel.
On 11/25/06, Jachym Cepicky <jachym.cepicky at centrum.cz> wrote:
> On Sat, Nov 25, 2006 at 06:56:14PM +0000, Glynn Clements wrote:
> > The documentation for the readlines() method says:
> >
> > readlines([sizehint])
> >
> > 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")
> > try:
> > for line in f:
> > print line
> > finally:
> > f.close()
>
> thanks, Glynn, but it does not seem to work - or it works the same way,
> like readlines() does.
>
> I have in the script:
>
> import os
> os.putenv("GRASS_MESSAGE_FORMAT","gui")
>
> f = os.popen("r.los --o in=elevation.dem out=tmp \
> coordinate=603067.6875,4925297.0625 max_dist=10000 2>&1")
> try:
> for line in f:
> print line
> finally:
> f.close()
>
> result is, lines are printed. but _after_ r.los finished it's
> calcualtions..
>
> do I understand something wrong?
>
> thanks
>
> jachym
>
> --
> Jachym Cepicky
> e-mail: jachym.cepicky at centrum.cz
> URL: http://les-ejk.cz
> GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
> -----------------------------------------
> OFFICE:
> Department of Geoinformation Technologies
> Zemedelska 3
> 613 00, Brno
> Czech Republick
> e-mail: xcepicky at node.mendelu.cz
> URL: http://mapserver.mendelu.cz
> Tel.: +420 545 134 514
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.3 (GNU/Linux)
>
> iD8DBQFFaJyXyKt0uAjU4I8RAmlTAKDUnIxJiatd2h/kU/OGv/LI/I1NSQCgn9BJ
> 1yFsraD4e8VY3nEZeozW3JM=
> =K8gc
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass-dev
>
>
--
-- Daniel Calvelo Aros
More information about the grass-dev
mailing list