_execvp,_wexecvp_execvp, _wexecvp

加载和执行新的子进程。Loads and executes new child processes.

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 _execvp(   
   const char *cmdname,  
   const char *const *argv   
);  
intptr_t _wexecvp(   
   const wchar_t *cmdname,  
   const wchar_t *const *argv   
);  

参数Parameters

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

argv
指向参数的指针的数组。Array of pointers to parameters.

返回值Return Value

如果成功,这些函数不返回到调用进程。If successful, these functions do not return to the calling process. 返回值-1 指示错误,在这种情况下errno设置全局变量。A return value of -1 indicates an error, in which case the errno global variable is set.

errnoerrno value 描述Description
E2BIG 自变量和环境设置所需的空间超过 32 KB。The space required for the arguments and environment settings exceeds 32 KB.
EACCES 指定的文件具有锁定或共享冲突。The specified file has a locking or sharing violation.
EINVAL 参数无效。Invalid parameter.
EMFILE 打开的文件太多 (必须打开指定的文件以确定它是否是可执行文件)。Too many files open (the specified file must be opened to determine whether it is executable).
ENOENT 未找到文件或路径。The file or path not found.
ENOEXEC 指定的文件不是可执行文件或者有无效的可执行文件格式。The specified file is not executable or has an invalid executable-file format.
ENOMEM 没有足够的内存可用于执行更新进程;可用内存损坏;或存在无效的块,指示调用进程未正确分配。Not enough memory is available to execute the new process; the available memory has been corrupted; or an invalid block exists, indicating that the calling process was not allocated properly.

有关这些属性和其他的更多信息返回代码示例,请参见 _doserrno、errno、_sys_errlist 和 _sys_nerrFor more information about these and other return codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.

备注Remarks

这些函数中的每个函数都将加载并执行一个新进程,并传递指向命令行参数的指针数组并使用 PATH 环境变量查找要执行的文件。Each of these functions loads 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.

_execvp 函数将验证其参数。The _execvp functions validate their parameters. 如果 cmdname 为空指针,或如果 argv 为空指针、指向一个空数组的指针,或者如果数组包含一个空字符串作为第一个实参,则这些函数调用无效的形参处理程序,如参数验证中所述。If the cmdname is a null pointer, or argv is a null pointer, pointer to an empty array, or if the array contains an empty string as the first argument, these functions invoke the invalid parameter handler as described in Parameter Validation. 如果允许执行继续,则这些功能将 errno 设置为 EINVAL 并返回 -1。If execution is allowed to continue, these functions set errno to EINVAL and return -1. 不启动任何进程。No process is launched.

要求Requirements

函数Function 必需的标头Required header 可选标头Optional header
_execvp <process.h><process.h> <errno.h><errno.h>
_wexecvp <process.h> 或 <wchar.h><process.h> or <wchar.h> <errno.h><errno.h>

有关更多兼容性信息,请参阅 兼容性For more compatibility information, see Compatibility.

示例Example

请参阅 _exec、_wexec 函数中的示例。See the example in _exec, _wexec Functions.

请参阅See Also

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