[GRASS-dev] Re: [Quantum GIS] #736: Some GRASS commands broken

Hi,

a colleague has found some strange problems in winQGIS/GRASS, signalled
to the QGIS team. I wonder if the problem could be GRASS related.

Hints welcome,
Markus

On Fri, Jun 29, 2007 at 11:15:19AM -0000, Quantum GIS wrote:

#736: Some GRASS commands broken
-----------------------+----------------------------------------------------
   Reporter: neteler | Owner: nobody
       Type: defect | Status: new
   Priority: major | Milestone:
  Component: GRASS | Version: 0.8.1
   Keywords: | Platform_version:
   Platform: Windows | Must_fix: No
Status_info: 0 |
-----------------------+----------------------------------------------------
Hi,

some GRASS commands are broken:

{{{
r.median base=CEA_cat@CEA_dati cover=CEA_aspect@CEA_dati
output=aspect_median

Illegal filename. Character <'> not allowed.
Illegal filename. Character <'> not allowed.
Raster map ['CEA_aspect@CEA_dati'] not found
Illegal filename. Character <'> not allowed.
r.stats: ['CEA_aspect@CEA_dati] not found

Successfully finished
}}}

-> unclear why ' is present

---------------------

{{{
r.mode base=delete cover=CEA_aspect output=del_aspetto

Illegal filename. Character <'> not allowed.
ERROR: r.stats: ['delete@CEA_dati] not found
Illegal filename. Character <'> not allowed.
Illegal filename. Character <'> not allowed.
ERROR: Raster map ['delete@CEA_dati'] not found
}}}

Same thing here.

---------------------

But r.average with the same syntax works perfectly.

---------------------

[unrelated]

--
Ticket URL: <https://svn.qgis.org/trac/ticket/736&gt;
Quantum GIS <http://qgis.org>
Quantum GIS is an Open Source GIS viewer/editor supporting OGR, PostGIS, and GRASS formats

Markus Neteler wrote:

a colleague has found some strange problems in winQGIS/GRASS, signalled
to the QGIS team. I wonder if the problem could be GRASS related.

Hints welcome,

> r.median base=CEA_cat@CEA_dati cover=CEA_aspect@CEA_dati
> output=aspect_median
>
> Illegal filename. Character <'> not allowed.

r.median invokes r.stats via system(), using a single quote:

    strcpy (command, "r.stats -a '");
    strcat (command, G_fully_qualified_name (basemap, base_mapset));
    strcat (command, ",");
    strcat (command, G_fully_qualified_name (covermap, cover_mapset));
    strcat (command, "'");

/* strcpy (command,"cat /tmp/t"); */
    stats_fd = popen (command, "r");

    sprintf (command, "r.reclass i='%s' o='%s'",
  G_fully_qualified_name (basemap, base_mapset), outmap);

system() uses the platform's shell: /bin/sh on Unix, cmd.exe on
Windows NT/2K/XP, command.com on 95/98/ME. Single quotes won't work
with the Windows shells.

r.average doesn't quote the map names, and uses double quotes around
the output filename:

    sprintf (command, "%s -anC input=%s,%s fs=space > \"%s\"",
  STATS, basemap->answer, covermap->answer, tempfile1);

Using double quotes should suffice so long as the map name doesn't
contain $ or ` (a double quote would also be problematic, but isn't
legal in map names).

Ultimately, we need a Windows implementation of G_spawn_ex(), so that
we can avoid the shell altogether.

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