_execvp,_wexecvp_execvp, _wexecvp

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

重要

此 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

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

argvargv
指向参数的指针的数组。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
E2BIGE2BIG 自变量和环境设置所需的空间超过 32 KB。The space required for the arguments and environment settings exceeds 32 KB.
EACCESEACCES 指定的文件具有锁定或共享冲突。The specified file has a locking or sharing violation.
EINVALEINVAL 参数无效。Invalid parameter.
EMFILEEMFILE 打开的文件太多 (必须打开指定的文件以确定它是否是可执行文件)。Too many files open (the specified file must be opened to determine whether it is executable).
ENOENTENOENT 未找到文件或路径。The file or path not found.
ENOEXECENOEXEC 指定的文件不是可执行文件或者有无效的可执行文件格式。The specified file is not executable or has an invalid executable-file format.
ENOMEMENOMEM 没有足够的内存可用于执行更新进程;可用内存损坏;或存在无效的块,指示调用进程未正确分配。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

所有这些函数将加载并执行新进程,将一个指针数组传递给命令行自变量和使用路径环境变量查找要执行的文件。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是 null 指针,指向一个空数组,或如果数组包含一个空字符串作为第一个参数,这些函数将调用无效参数处理程序如中所述参数验证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. 如果允许继续执行,这些函数将设置errnoEINVAL并返回-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_execvp <process.h><process.h> <errno.h><errno.h>
_wexecvp_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
abortabort
atexitatexit
exit、_Exit、_exitexit, _Exit, _exit
_onexit、_onexit_m_onexit, _onexit_m
_spawn、_wspawn 函数_spawn, _wspawn Functions
system、_wsystemsystem, _wsystem