_spawnvp, _wspawnvp
Create and execute a new process.
intptr_t _spawnvp(
int mode,
const char *cmdname,
const char *const *argv
);
intptr_t _wspawnvp(
int mode,
const wchar_t *cmdname,
const wchar_t *const *argv
);
Parameters
mode
Execution mode for calling processcmdname
Path of file to be executedargv
Array of pointers to arguments. The argument argv[0] is usually a pointer to a path in real mode or to the program name in protected mode, and argv[1] through argv[n] are pointers to the character strings forming the new argument list. The argument argv[n +1] must be a NULL pointer to mark the end of the argument list.
Return Value
The return value from a synchronous _spawnvp or _wspawnvp (**_**P_WAIT specified for mode) is the exit status of the new process. The return value from an asynchronous _spawnvp or _wspawnvp (_P_NOWAIT or _P_NOWAITO specified for mode) is the process handle. The exit status is 0 if the process terminated normally. You can set the exit status to a nonzero value if the spawned process specifically calls the exit routine with a nonzero argument. If the new process did not explicitly set a positive exit status, a positive exit status indicates an abnormal exit with an abort or an interrupt. A return value of –1 indicates an error (the new process is not started). In this case, errno is set to one of the following values:
E2BIG
Argument list exceeds 1024 bytesEINVAL
mode argument is invalidENOENT
File or path is not foundENOEXEC
Specified file is not executable or has invalid executable-file formatENOMEM
Not enough memory is available to execute new process
See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, return codes.
Remarks
Each of these functions creates and executes a new process, passing an array of pointers to command-line arguments and using the PATH environment variable to find the file to execute.
These functions validate their parameters. If either cmdname or argv is a null pointer, or if argv points to null pointer, or argv[0] is an empty string, the invalid parameter handler is invoked, as described in Parameter Validation . If execution is allowed to continue, these functions set errno to EINVAL, and return -1. No new process is spawned.
Requirements
Routine |
Required header |
---|---|
_spawnvp |
<stdio.h> or <process.h> |
_wspawnvp |
<stdio.h> or <wchar.h> |
For additional compatibility information, see Compatibility in the Introduction.
Example
See the example in _spawn, _wspawn Functions.