[GRASS-user] Re: [GRASS-dev] Helpp needed to call Grass from inside Python Plugin

Glynn Clements glynn at gclements.plus.com
Wed Mar 24 22:20:45 EDT 2010


Bishwarup Banerjee wrote:

> I have tried to iimplement the example in my way. The code is as follows

> import core as grass

This should be:

	import grass.script as grass
or:
	import grass.script.core as grass

> def main():
>     input_map = options['H:/Shared_data/test1.tif']
>     output_map = options['Test_24']

This is bogus. The keys in the "options" dictionary are the names of
the options defined in the g.parser comments (assuming that you have
them; if you don't, grass.parser() won't work).

> But I get the following error, I cant make out where I am going wrong. I
> have set all the Env variables as suggested in the wiki page. Please help me
> to implement it.
> 
> 
> F:\GRASS-6-SVN\etc\python\grass\script>python test.py
> Traceback (most recent call last):
>   File "test.py", line 18, in <module>
>     options, flags = grass.parser()
>   File "F:\GRASS-6-SVN\etc\python\grass\script\core.py", line 359, in parser
>     os.execvp("g.parser.exe", [name] + argv)
>   File "F:\Quantum GIS\python\os.py", line 353, in execvp
>     _execvpe(file, args)
>   File "F:\Quantum GIS\python\os.py", line 389, in _execvpe
>     func(fullname, *argrest)
> OSError: [Errno 22] Invalid argument

I have no idea what's causing this.

I suggest modifying the parser() function to print the arguments which
are being passed to os.execvp():

>   File "F:\GRASS-6-SVN\etc\python\grass\script\core.py", line 359, in parser
>     os.execvp("g.parser.exe", [name] + argv)

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


More information about the grass-user mailing list