[GRASS-user] Problems with GRASS python code in osgeo4w
Glynn Clements
glynn at gclements.plus.com
Mon Jun 22 18:40:59 EDT 2009
Hamish wrote:
> > So, I still don't know why the grass.parser() is not
> > working for me. I even modified my program to use pdb
> > to see what is happening. The debugger is aborted
> > right after I reach os.execvp("g.parser.exe", [name] + argv)
> > in grass.py. But if I use "python
> > c:\osgeo4w\apps\grass\grass-6.4.0svn\scripts\m.dipslope.py --help",
> > I get the expected results.
>
>
> try putting 'c:\osgeo4w\apps\grass\grass-6.4.0svn\scripts' in your %PATH%.
> when g.parser is complete it reruns the script but only by its filename.
g.parser uses the filename passed as argv[1]. This needs to be the
complete path to the script, so that g.parser can fopen() it and read
the #% comments; PATH won't help here.
Unix shells normally have the full pathname as $0 (the kernel sees the
#!/bin/sh line and invokes /bin/sh with the full path to the script).
On Windows, shell scripts are invoked via windows_launch.bat, which
invokes the script by its full path.
The Python parser() function attempts to construct an absolute path,
but I don't know if this is working; it doesn't look like it. The
--help option is handled without re-invoking the script; if that
doesn't work, it suggests that g.parser cannot fopen() the script.
> If the script isn't in the PATH* it fails at that point because it
> can't find it. The above seems like it should be in the path.. do other
> "official" scripts in that directory work?
>
> [*] (the current dir is typically also checked in MS Windows although it
> typically is not in UNIX)
>
> see also GRASS_ADDONS_PATH enviro variable.
>
> for grass 7 Glynn may have just changed this a couple of days ago??
I have, but it won't make any difference in this case.
FWIW, the changes involve adding a -s switch. When used, g.parser
doesn't re-invoke the script; it simply writes all of the flag and
option settings to stdout. The Python parser() interface then parses
this output.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list