spawnl, spawnle, spawnlp, spawnlpe, spawnv, spawnve, spawnvp, spawnvpe
Creates and runs child processes.
Defined in header <process.h>
Syntax
#include <process.h>
#include <stdio.h>
int spawnKint mode, char *path, char *argO, argl,...,argn,NULL);
int spawnle(int mode, char *path, char *argO, argl,...,argn,NULL,
char *envpU);
int spawnlp(int mode, char *path, char *argO,argl, ...,argn,NULL);
int spawnlpe(int mode, char *path, char *argO,argl, ...,argn,NULL, char
*envpU);
int spawnv(int mode, char *path, char *argv[]);
int spawnve(int mode, char *path, char *argv[],char *envp[]);
int spawnvp(int mode, char *path, char *argv[]);
int spawn vpe(int mode, char *path, char *argv[],char *envpl]);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Remarks
The functions in the spawn... family create and run (execute) other files, known as child processes. There must be sufficient memory available for loading and executing a child process.
The value of mode determines what action the calling function (the parent process) takes after the spawn... call. The possible values of mode are
| PWAIT | Puts parent process "on hold" until child process completes execution. |
| PNOWAIT | Continues to run parent process while child process runs. |
| POVERLAY | Overlays child process in memory location formerly occupied by parent. Same as an exec... call. |
| PNOWAIT path is the file name of the called child process. The spawn... function calls search for path using the standard DOS search algorithm: | is currently not available; using it generates an error value. |
m No extension or no period: Search for exact file name; if not successful, DOS adds .COM and searches again. If still not successful, it adds .EXE and searches again. Q Extension given: Search only for exact file name. Q Period given: Search only for file name with no extension. □ If path does not contain an explicit directory, spawn... functions that have the p suffix will search the current directory, then the directories set with the DOS PATH environment variable.
The suffixes /, v, p, and e added to the spawn... "family name" specify that the named function operates with certain capabilities.
p The function will search for the file in those directories specified by the PATH environment variable. Without the p suffix, the function will search only the current working directory.
I The argument pointers argO, argl, ..., argn are passed as separate arguments. Typically, the / suffix is used when you know in advance the number of arguments to be passed.
V The argument pointers argv[0], ..., argln] are passed as an array of pointers. Typically, the v suffix is used when a variable number of arguments is to be passed.
e The argument envp can be passed to the child process, allowing you to alter the environment for the child process. Without the e suffix, child processes inherit the environment of the parent process.
Each function in the spawn... family must have one of the two argument-specifying suffixes (either lorv). The path search and environment inheritance suffixes (p and e) are optional.
For example,
B spawnl takes separate arguments, searches only the current directory for the child, and passes on the parent's environment to the child. B spawnvpe takes an array of argument pointers, incorporates PATH in its search for the child process, and accepts the envp argument for altering the child's environment.
The spawn... functions must pass at least one argument to the child process (argO or argv[0]): This argument is, by convention, a copy of path. (Using a different value for this 0th argument won't produce an error.) If you want to pass an empty argument list to the child process, then argO or argvlO] must be NULL.
Under DOS 3.x, path is available for the child process; under earlier versions, the child process cannot use the passed value of the 0th argument {argO or argv[0]).
When the / suffix is used, argO usually points to path, and argl, ...., argn point to character strings that form the new list of arguments. A mandatory null following argn marks the end of the list.
When the e suffix is used, you pass a list of new environment settings through the argument envp. This environment argument is an array of character pointers. Each element points to a null-terminated character string of the form
envvar = value
where envvar is the name of an environment variable, and value is the string value to which envvar is set. The last element in envpl] is null. When envp is null, the child inherits the parents' environment settings.
The combined length of argO + argl + ... + argn (or of argv[0] + argv[l] + ... + argv[n]), including space characters that separate the arguments, must be < 128 bytes. Null-terminators are not counted.
When a spawn... function call is made, any open files remain open in the child process.
Return value
On a successful execution, the spawn... functions return the child process's exit status (0 for a normal termination). If the child specifically calls exit with a nonzero argument, its exit status can be set to a nonzero value.
On error, the spawn... functions return -1, and the global variable errno is set to
| E2BIG | Arg list too long |
| EINVAL | Invalid argument |
| ENOENT | Path or file name not found |
| ENOEXEC | Exec format error |
| ENOMEM | Not enough core |
See also
Example
#include <process.h>
#include <stdio.h>
#include <conio.h>
void spawnl_example (void)
int result;
clrscr ();
result = spawnl (PJJAIT, "bcc.exe", NULL);
if (result == -1) {
perror( "Error from spawnl");
exit(l); . ,
void spawnle_example(void)
{
int result;
clrscr ();
result = spawnle {P_WAIT, "bcc.exe", NULL, NULL);
if (result == -1) {
perror( "Error from spawnle");
exit (1) ;
}
}
int main (void)
{
spawnl_example( );
spawnle_example ();
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/process.h/spawnl/
· short form /3.1/spawnl/