On Saturday 04 May 2024 23:46:03 LIU Hao wrote:
> 在 2024-05-04 20:18, Pali Rohár 写道:
> > msvcrt's execve splits every member of arglist to more arguments by
> > space. If you want to prevent this splitting then you need to quote
> > argument as:
> 
> Each Windows process receives its command-line arguments as a whole string
> and has to parse it with `__getmainargs()`, unlike on Linux etc. where
> arguments are passed directly as a `char**`.

I know. The point is that msvcrt's _execve() is not compatible with
msvcrt's __getmainargs().

There is a convention which applications follow to convert argv[] array
into single string command-line and vice-versa. It matches getmainargs.
But _exec* and _spawn* do not follow it, which makes these two functions
hard to use...

> 
> > So in my opinion, for compatibility with POSIX (when one of those macro
> > is defined, like _POSIX_C_SOURCE) then mingw-w64 should provide also
> > POSIX compatible execve() function wrapper.
> 
> I think that nobody would ever prefer `_execve()` because it's a Unix relic.
> It would not be very useful without `fork()`.

execve() may be useful also without fork() - for wrapper purposes.
When executable A wants to just to redirect control to executable B.

But I agree that most common usage is fork()+exec*()

> And we probably should not be reproducing Unix too much.

Makes sense. Better is to let this execve() issue as is.


On a side note, I think that implementing posix_spawn() can be useful.
It can be implemented as a simple wrapper around msvcrt spawn() with
argv[] handling compatible with msvcrt __getmainargs().


_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to