[GRASS-dev] Re: testing native winGRASS
Glynn Clements
glynn at gclements.plus.com
Mon Mar 19 12:02:34 EDT 2007
Moritz Lennert wrote:
> > I'm not sure. It would be nice if someone would volunteer to write the
> > Windows implementation (using CreateProcess()).
>
> I guess this means more than just replacing
>
> execvp(command, args);
>
> by a
>
> CreateProcess() equivalent ?
On Unix, spawning a child is a two-step process: fork() and exec().
Typically, the calling program changes various aspects of the child
process between the two. E.g. redirecting stdout to a file:
pid = fork();
if (pid == 0) /* we're the child */
{
/* open file */
int fd = open(outfile, O_WRONLY|O_CREAT, 0666);
/* attach it to stdout */
dup2(fd, 1);
/* run the program */
execvp(<program>);
}
On Windows, there is only one step, CreateProcess(), which has various
options to set the environment, current directory, std{in,out,err}
etc.
The tricky part is that CreateProcess() takes a single string as the
command line; this would have to be constructed from the individual
arguments using appropriate[1] quoting.
[1] I'm not entirely sure of the rules here. I don't even know if
Microsoft knows; their spawn* functions fail to correctly handle
arguments which contain spaces, which implies that spawn* ignore the
issue and simply concatenate their arguments with a space between each
one.
In the absence of further information, I would suggest simply putting
double quotes around each argument and spaces in between. That should
be better than spawn*, and probably as good as doing the same thing
using system(). I don't even know if it's possible to do it "right" on
Windows (i.e. pass arguments containing quotes or other "special"
characters).
More details at:
http://msdn2.microsoft.com/en-us/library/ms682425.aspx
http://msdn2.microsoft.com/en-us/library/20y988d2(VS.80).aspx
> >
> > Hmm. We might want a function which returns the name of the platform's
> > null device (i.e. /dev/null on Unix, NUL: on Windows).
>
> Would this just be a function returning 'NUL' or '/dev/null' as a
> string, or do we have to get the name of the null device from the system ?
No, it would just be returning a literal string, conditionalised upon
"#ifdef __MINGW32__".
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list