I just had a very unpleasant experience when trying to use the _spawnl() function...
The MSDN says the syntax is:
Code:
intptr_t _spawnl(
int mode,
const char *cmdname,
const char *arg0,
const char *arg1,
... const char *argn,
NULL
);
So I ran it as:
Code:
_spawnl( _P_NOWAIT, "UserExit.bat", "ChangePassword", "User1", "Password", NULL );
My UserExit.bat file calls ChangePassword.bat (depending on the parameters passed)... but I noticed that UserExit.bat was never getting called, but somehow ChangePassword.bat was called. For almost a day I thought I was going crazy. Then after looking at some examples that use _spawnl() I noticed that they always pass the same value for the 2nd & 3rd parameters. That's when I realized that the arg0 in the MSDN syntax relates to the argv[0] that gets passed to programs (i.e. the program name), not the first real parameter.
Obviously when I passed "UserExit.bat" twice everything was working fine, but what I found so strange is that it was calling "ChangePassword.bat" (i.e. using the arg0 parameter as the program to run) instead of "UserExit.bat" which is listed as cmdname. Is this a bug in _spawnl()? Why would it run the arg0 parameter, and if that's what it actually does, then what's the point of even specifying a cmdname parameter?