C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
_exec Functions
 Summary Example                         Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
     The _exec functions load and execute new child processes. When the
     call is successful in DOS, the child process is placed in the
     memory previously occupied by the calling process. Sufficient
     memory must be available for loading and executing the child
     process.
 
     All of the functions in the _exec family use the same _exec
     function. The letter(s) at the end of the function name determine
     the specific variation, as listed below:
 
     Letter     Variation
 
     p          The PATH environment variable is used to find the file
                to be executed.
 
     l          Command-line arguments are passed to the _exec function
                individually.
 
     v          Command-line arguments are passed to the _exec function
                as an array of pointers.
 
     e          An array of pointers to environment arguments is
                explicitly passed to the child process.
 
     The <cmdname> argument specifies the file to be executed as the
     child process. It can specify a full path (from the root), a
     partial path (from the current working directory), or just a
     filename.
 
     If <cmdname> does not have a filename extension or does not end
     with a period (.), the _exec function searches for the named file.
     If the search is unsuccessful, it tries the same base name first
     with the extension .COM, then with the extension .EXE. If
     <cmdname> has an extension, only that extension is used in the
     search. If <cmdname> ends with a period, the _exec function
     searches for <cmdname> with no extension.
 
     The _execlp, _execlpe, _execvp, and _execvpe routines search for
     <cmdname> (using the same procedures) in the directories specified
     by the PATH environment variable. If <cmdname> contains a drive
     specifier or any slashes (that is, if it is a relative path name),
     the _exec call searches only for the specified file. It does not
     search the path.
 
     Arguments are passed to the new process by giving one or more
     pointers to character strings as arguments in the _exec call.
     These character strings form the argument list for the child
     process. The combined length of the strings forming the argument
     list for the new process must not exceed 128 bytes (in real mode
     only). The terminating null character (\0) for each string is not
     included in the count, but space characters (inserted
     automatically to separate the arguments) are counted.
 
     The argument pointers can be passed as separate arguments (_execl,
     _execle, _execlp, and _execlpe) or as an array of pointers
     (_execv, _execve, _execvp, and _execvpe). At least one argument,
     <arg0>, must be passed to the child process (which sees it as
     <argv[0]>). Usually, this argument is a copy of the <cmdname>
     argument. (A different value does not produce an error.)
 
     Under versions of DOS earlier than 3.0, the passed value of <arg0>
     is not available for use in the child process. With DOS versions
     3.0 and later, the <cmdname> is available as <arg0>.
 
     The _execl, _execle, _execlp, and _execlpe calls are typically
     used when the number of arguments is known in advance. The <arg0>
     argument is usually a pointer to <cmdname>. The <arg1> through
     <argn> arguments point to the character strings forming the new
     argument list. A NULL pointer must follow <argn> to mark the end
     of the argument list.
 
     The _execv, _execve, _execvp, and _execvpe calls are useful when
     the number of arguments to the new process is variable. Pointers
     to the arguments are passed as an array, <argv>. The <argv[0]>
     argument is usually a pointer to <cmdname>. The <argv[1]> through
     <argv[n]> arguments point to the character strings forming the new
     argument list. The <argv[n+1]> argument must be a NULL pointer to
     mark the end of the argument list.
 
     Files that are open when an _exec call is made remain open in the
     new process. In the _execl, _execlp, _execv, and _execvp calls, the
     child process inherits the environment of the parent. The _execle,
     _execlpe, _execve, and _execvpe calls allow you to alter the
     environment for the child process by passing a list of environment
     settings through the <envp> argument. The <envp> argument is an
     array of character pointers, each element of which (except for the
     final element) points to a null-terminated string defining an
     environment variable. Such a string usually has the form
 
          NAME=value
 
     where NAME is the name of an environment variable and <value> is
     the string value to which that variable is set. (Note that <value>
     is not enclosed in double quotation marks.) The final element of
     the <envp> array should be NULL. When <envp> itself is NULL, the
     child process inherits the environment settings of the parent
     process.
 
     A program executed with one of the _exec functions is always
     loaded into memory as if the "maximum allocation" field in the
     program's .EXE file header is set to the default value of 0XFFFFH.
     You can use the EXEHDR utility to change the maximum allocation
     field of a program. However, the program's behavior when invoked
     with one of the _exec functions may be different from when it is
     invoked directly from the operating-system command line or with
     one of the _spawn functions.
 
     The _exec calls do not preserve the translation modes of open
     files. If the child process must use files inherited from the
     parent, the _setmode routine should be used to set the translation
     mode of these files to the desired mode.
 
     You must explicitly flush (using fflush or _flushall) or close any
     stream prior to the _exec function call.
 
     Signal settings are not preserved in child processes created by
     calls to _exec routines. The signal settings are reset to the
     default in the child process.
 
     Because of differences in DOS versions 2.0 and 2.1, child
     processes generated by the _exec family of functions (or by the
     equivalent _spawn functions with the _P_OVERLAY argument) can
     cause fatal system errors when they exit. If you are running DOS
     2.0 or 2.1, you must upgrade to DOS version 3.0 or later in order
     to use these functions.
 
     Return Value
 
     The _exec functions do not normally return to the calling process.
     If an _exec function returns, an error has occurred and the return
     value is -1. The errno variable is set to E2BIG, EACCES, EMFILE,
     ENOENT, ENOEXEC, or ENOMEM.
                                    -♦-