[GRASS-dev] Using --quiet flag in grass.run_command

Greetings

I’m running a few functions inside grass.run_command and I wanted to use the --quiet flag but I cannot find any information about it. I have tried flag=‘q’, flag=‘–quiet’ and jut ‘–quiet’ but non of these are accepted.

Can anyone give me an hand?
Thanks
Helena

Hi,

2010/10/18 Helena Herrera <helenaherrera1980@gmail.com>:

I'm running a few functions inside grass.run_command and I wanted to use the
--quiet flag but I cannot find any information about it. I have tried
flag='q', flag='--quiet' and jut '--quiet' but non of these are accepted.

use `quiet` flag instead, e.g.

grass.run_command(v.build, map = "name", quiet = True)

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Martin Landa wrote:

> I'm running a few functions inside grass.run_command and I wanted to use the
> --quiet flag but I cannot find any information about it. I have tried
> flag='q', flag='--quiet' and jut '--quiet' but non of these are accepted.

use `quiet` flag instead, e.g.

grass.run_command(v.build, map = "name", quiet = True)

Similarly, "verbose = True" for --verbose and "overwrite = True" for
--overwrite.

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

Hi there
I have tried:
check_input= grass.run_command(“g.findfile”, element=‘cell’, file=i, mapset=mapsetc, quiet=“True”)
and I still got that boring print . What am I missing?
Thanks

On Mon, Oct 18, 2010 at 11:06 AM, Glynn Clements <glynn@gclements.plus.com> wrote:

Martin Landa wrote:

I’m running a few functions inside grass.run_command and I wanted to use the
–quiet flag but I cannot find any information about it. I have tried
flag=‘q’, flag=‘–quiet’ and jut ‘–quiet’ but non of these are accepted.

use quiet flag instead, e.g.

grass.run_command(v.build, map = “name”, quiet = True)

Similarly, “verbose = True” for --verbose and “overwrite = True” for
–overwrite.


Glynn Clements <glynn@gclements.plus.com>

Hi,

2010/10/18 Helena Herrera <helenaherrera1980@gmail.com>:

check_input= grass.run_command("g.findfile", element='cell', file=i,
mapset=mapsetc, quiet="True")
and I still got that boring print . What am I missing?

verbosity level (quiet/verbose) only affects printing
messages/warnings. In this case 'g.findfile' prints its output to
stdout, so it's printed regardless of quite or verbose flags.

Run

file = grass.read_command('g.findfile', element = 'cell', file='x',
quiet = True)
print file

or better grass.find_file directly (interface for 'g.findfile')

file = grass.find_file(element = 'cell', name = 'x')
print file

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

In some functions, for instance g.remove even after using quiet=True ther warnings are still beng printed. was tha expected?

Regarding GDALWARP, I’m running this command:
grass.debug(“gdalwarp -t_srs %s -srcnodata %s -dstnodata %s -tr %s %s %s %s” % (proj_location, no_value, no_value, t_srx, t_sry, input, tempfile))
can I use something in order to avoid all the printing that this does?

On Mon, Oct 18, 2010 at 1:23 PM, Martin Landa <landa.martin@gmail.com> wrote:

[please keep discussion on ML]

2010/10/18 Helena Herrera <helenaherrera1980@gmail.com>:

Maybe I was not clear. What GRASS is doing is printing and I don’t want ot
print those messages. So, what you are saying is that I’m not able to avoid
the printing og g.findfile?

as I wrote in the previous mail use grass.find_file(). Seems to me
that I am not understanding well, running

grass.run_command(‘g.findfile’, …, stdout = file(os.devnull, ‘w’))

is quite meaningless.

Martin


Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Helena Herrera wrote:

In some functions, for instance g.remove even after using quiet=True ther
warnings are still beng printed. was tha expected?

--quiet suppresses messages; it doesn't suppress warnings.

Regarding GDALWARP, I'm running this command:
grass.debug("gdalwarp -t_srs %s -srcnodata %s -dstnodata %s -tr %s %s %s %s"
% (proj_location, no_value, no_value, t_srx, t_sry, input, tempfile))
can I use something in order to avoid all the printing that this does?

You can redirect stdout and/or stderr to the null device (/dev/null on
Unix, "nul" on Windows), e.g.:

  nullf = open(os.devnull, 'w')
  grass.run_comand(..., stdout = nullf, stderr = nullf)
  nullf.close()

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