_spawnvp、_wspawnvp_spawnvp, _wspawnvp

创建并执行进程。Creates a process and executes it.

Important

此 API 不能用于在 Windows 运行时中执行的应用程序。This API cannot be used in applications that execute in the Windows Runtime. 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数For more information, see CRT functions not supported in Universal Windows Platform apps.

语法Syntax

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 the process.

cmdname
要执行的文件的路径。Path of the file to be executed.

argv
指向参数的指针的数组。Array of pointers to arguments. 参数 argv[0] 通常是一个指向实际模式中的路径或保护模式中的程序的指针, argv[1] 至 argv[n] 是指向形成新的参数列表的字符串的指针。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 that form the new argument list. 参数 argv[n +1] 必须是一个 NULL 指针,用以标记参数列表的末尾。The argument argv[n +1] must be a NULL pointer to mark the end of the argument list.

返回值Return Value

同步 _spawnvp_wspawnvp(为 _P_WAIT 指定的 mode)中的返回值是新进程的退出状态。The return value from a synchronous _spawnvp or _wspawnvp (_P_WAIT specified for mode) is the exit status of the new process. 异步 _spawnvp_wspawnvp (为_P_NOWAIT 指定的 _P_NOWAITOmode)的返回值是进程句柄。The return value from an asynchronous _spawnvp or _wspawnvp (_P_NOWAIT or _P_NOWAITO specified for mode) is the process handle. 如果进程正常终止,则退出状态为 0。The exit status is 0 if the process terminated normally. 如果生成进程专门使用非零参数调用 exit 例程,则可以将退出状态设置为一个非零值。You can set the exit status to a nonzero value if the spawned process specifically uses a nonzero argument to call the exit routine. 如果更新过程没有显式设置正退出状态,则正退出状态指示因中止或中断而异常退出。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. 返回值-1 指示的错误 (不启动新过程)。A return value of -1 indicates an error (the new process is not started). 在这种情况下,errno 设置为下列值之一:In this case, errno is set to one of the following values:

E2BIG
参数列表超过 1024 个字节。Argument list exceeds 1024 bytes.

EINVAL
mode 参数无效。mode argument is invalid.

ENOENT
未找到文件或路径。File or path is not found.

ENOEXEC
指定的文件不是可执行文件或者有无效的可执行文件格式。Specified file is not executable or has invalid executable-file format.

ENOMEM
没有足够的内存可用于执行新进程。Not enough memory is available to execute the new process.

有关这些和其他返回代码的详细信息,请参阅 errno、_doserrno、_sys_errlist 和 _sys_nerrFor more information about these, and other, return codes, see errno, _doserrno, _sys_errlist, and _sys_nerr.

备注Remarks

这些函数中的每个函数都将创建并执行一个新进程,并传递指向命令行参数的指针数组并使用 PATH 环境变量查找要执行的文件。Each of these functions creates a new process and executes it, and passes an array of pointers to command-line arguments and uses the PATH environment variable to find the file to execute.

这些函数验证其参数。These functions validate their parameters. 如果 cmdnameargv 是 null 指针,或者 argv 指向 null 指针或 argv[0] 是空字符串,则调用的参数处理程序无效,如 Parameter Validation中执行的应用程序。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. 如果允许执行继续,则这些功能将 errno 设置为 EINVAL,并返回 -1。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> 或 <process.h><stdio.h> or <process.h>
_wspawnvp <stdio.h> 或 <wchar.h><stdio.h> or <wchar.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

在参见 _spawn、_wspawn 函数中的示例。See the example in _spawn, _wspawn Functions.

请参阅See Also

进程和环境控制 Process and Environment Control
_spawn、_wspawn 函数 _spawn, _wspawn Functions
abort abort
atexit atexit
_exec、_wexec 函数 _exec, _wexec Functions
exit、_Exit、_exit exit, _Exit, _exit
_flushall _flushall
_getmbcp _getmbcp
_onexit、_onexit_m _onexit, _onexit_m
_setmbcp _setmbcp
system、_wsystemsystem, _wsystem