[GRASS-dev] erratic behavior of v.in.ascii with WinGRASS
Glynn Clements
glynn at gclements.plus.com
Thu Feb 7 09:43:44 EST 2008
Michael Barton wrote:
> > If the string is parsed by the shell, it needs to be quoted, otherwise
> > it doesn't.
> >
> >> Given these tests and what Glynn said (subsequent post), it seems
> >> safest to always quote or escape the | character in v.in.ascii. In
> >> this regard, is there a problem with making the default separator for
> >> the g.parser section of v.in.ascii "|" instead of the current | ?
> >
> > Yes. That would cause the quotes to be treated as part of the argument
> > to the fs= option.
>
> I don't understand. Helena suggested that I put quotes around "|",
> which I did and which worked--from the GUI. So why not make this the
> default
Because the quotes will become part of the value of the fs= option, so
both the double quote character and the vertical bar character will be
treated as field separators. That will be a problem if you have any
double quote characters within the data.
If you want to pass | as the argument to fs=, pass |, don't pass a
string containing both | and ".
> >> As an aside, the | character seems like an odd default separator for
> >> data fields in GRASS. I suppose it's a holdover from the ancient
> >> past. But the fact that this is also has meaning as a pipe seems to
> >> make it a risky separator in general. What about switching this to
> >> something else in GRASS 7?
> >
> > There's only thing that's "risky" about using "|" is that certain bugs
> > in code which executes commands will show up rather than getting
> > overlooked.
> >
> > If such bugs exist, they should be fixed, rather than having
> > individual cases worked around.
>
> OK. But I don't understand what needs to be fixed here (though I'd be
> happy to have whatever needs to be fixed, fixed). I'm hearing quote
> the | character and don't quote the | character. So I'm confused.
To use the | character as the field separator, you want to ensure that
one element in the argv[] passed to v.in.ascii's main function is
exactly equal to "fs=".
How you do that depdends upon how you're invoking v.in.ascii. E.g. if
you're using the C execl() function:
execl("v.in.ascii", "v.in.ascii", "fs=|", <other arguments>, NULL);
If you're using Tcl's "open":
set h [open |v.in.ascii fs=| <other arguments>]
If you're using the shell:
v.in.ascii fs='|' <other arguments>
or:
v.in.ascii fs=\| <other arguments>
or:
v.in.ascii "fs=|" <other arguments>
Python's subprocess.Popen():
p = Popen(["v.in.ascii", "fs=|", <other arguments>])
And so on.
What matters is that you get a specific string to appear in some
member of argv[].
If you're not sure what's ending up in argv[], add some debugging
statements, or replace the target program with something like the
following:
#include <stdio.h>
int main(int argc, const char * const * const argv)
{
int i;
for (i = 0; i < argc; i++)
printf("argv[%2d]: %s\n", i, argv[i]);
return 0;
}
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list