[GRASS-dev] gis.m in wingrass: using where clause in d.vect causes error :can't read "_data(.gronsole.gronsole, 9, donecmd)": no such element in array

Glynn Clements glynn at gclements.plus.com
Mon Oct 23 20:49:32 EDT 2006


Moritz Lennert wrote:

> > IOW, "sh -c '$cmd'" will only work for commands where none of the
> > arguments contain either Tcl or shell metacharacters. If you want to
> > invoke $cmd via "sh -c ...", you have to take the list apart and
> > construct a command line using shell syntax.
> >
> > E.g. (untested):
> >
> > 	set shcmd ""
> > 	foreach arg $cmd {
> > 		set arg2 [regsub -all {'} $arg {'\''}]
> > 		if {$shcmd == ""} {
> > 			set shcmd "'$arg2'"
> > 		} else {
> > 			set shcmd "$shcmd '$arg2'"
> > 		}
> > 	}
> > 	set cmd [concat | sh -c $shcmd]
> 
> Finally gotten around to trying this. After adding simple quotes to the
> last line:
> 
>       set cmd [concat | sh -c '$shcmd']

That's wrong. There definitely shouldn't be quotes around the command
as a whole. If it doesn't work without them, that suggests that
something else is messing with the command.

> > However, for various reasons, it would be better if we could find a
> > way avoid using "sh -c ..." altogether. The problem there is that you
> > can't directly execute shell scripts on Windows.
> 
> agreed, but have we found a way for doing this, yet, at least theoretically ?

Execute commands via a launcher program.

The launcher would first locate the executable named by its first
argument. If it's an absolute path, use it directly, otherwise search
the execution path.

If it finds a match with a known executable suffix (.exe, .bat, .cmd
etc), execute that.

If it finds a match with no suffix, open the file, and check whether
the first two bytes are "#!". If they are, read the interpreter (e.g. 
"/bin/sh") from the script, look up the corresponding program in a
table of known interpreters, and run the interpreter with the script
filename as the first argument, followed by the command's arguments.

This is essentially what the Unix kernel does when you call execve(),
and what Unix emulation layers such as Cygwin or MSys' bash do. Using
"sh -c ..." with MSys is using the execve() emulation in MSys' bash,
but bash is a rather heavy-weight solution. A launcher that just
identifies scripts and does nothing else would be preferable.

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




More information about the grass-dev mailing list