home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLIBSRC3.ZIP / EXECVPE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  5.3 KB  |  113 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - execvpe.c
  3.  *
  4.  * function(s)
  5.  *        execvpe - load and execute a program
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <process.h>
  18. #include <_process.h>
  19.  
  20. /*---------------------------------------------------------------------------*
  21.  
  22. Name            exec... - functions that load and run other programs
  23.  
  24. Usage           int  execvpe(char *pathname, char *argv[], char *envp[]);
  25.  
  26. Prototype in    process.h
  27.  
  28. Description     The functions in the exec...  family load and run (execute)
  29.                 other programs,  known as child processes.  When an exec...
  30.                 call is  successful, the child process  overlays the parent
  31.                 process.  There  must  be  sufficient  memory available for
  32.                 loading and executing the child process.
  33.  
  34.                 pathname is the file name  of the called child process. The
  35.                 exec...  functions search  for pathname  using the standard
  36.                 MS-DOS search algorithm:
  37.  
  38.                         . If no explicit extension is given, the function
  39.                           will search for the file as given. If that one is
  40.                           not found, the function will add .COM and search
  41.                           again. If that's not found, it will add .EXE and
  42.                           search one last time.
  43.  
  44.                         . If an explicit extension or period is given, the
  45.                           function will search for the file as given.
  46.  
  47.                 The suffixes l,  v, p and e added to  exec... "family name"
  48.                 specify that  the named function will  operate with certain
  49.                 capabilities.
  50.  
  51.                         p specifies  that the function will  search for the
  52.                           child in  those directories specified by  the DOS
  53.                           PATH environment variable. If pathname does not
  54.                           contain an explicit directory the function will
  55.                           search first the current directory then in the
  56.                           directory specified by the path. Without the p
  57.                           suffix, the  function only  searches the current
  58.                           working directory.
  59.  
  60.                         l specifies that the argument pointers (arg0, arg1,
  61.                           ...,  argn)  are  passed  as  separate arguments.
  62.                           Typically, the l suffix is  used when you know in
  63.                           advance the  number of arguments to  be passed. A
  64.                           mandatory  NULL following  argn marks  the end of
  65.                           the list.
  66.  
  67.                         v specifies  that  the argument  pointers (argv[0],
  68.                           argv[1], ..., argv[n]) are  passed as an array of
  69.                           pointers.  Typically,  the  v  suffix  is  used a
  70.                           variable number of arguments is to be passed.
  71.  
  72.                         e specifies that the  argument envp maybe passed to
  73.                           the  child  process,  allowing  you  to alter the
  74.                           environment for the child  process. Without the e
  75.                           suffix, child process inherits the environment of
  76.                           the parent process.  This environment argument is
  77.                           an  array of  char *.  Each element  points to  a
  78.                           null-terminated character string of the form:
  79.  
  80.                                 envar=value
  81.  
  82.                           where  envar  is  the   name  of  an  environment
  83.                           variable, and value is  the string value to which
  84.                           envar is set. The last element of envp[] is NULL.
  85.                           When  envp[0]  is  NULL,  the  child inherits the
  86.                           parent's environment settings.
  87.  
  88.                 The  exec... functions  must at  least one  argument to the
  89.                 child process. This  argument is, by convention, a  copy of
  90.                 pathname.  Under MS-DOS  3.x, pathname is available for the
  91.                 child process; under earlier versions, the child cannot use
  92.                 the passed value of arg0 (or argv[0]).
  93.  
  94.                 When  an exec...  function call   is made,  any open  files
  95.                 remain open in the child process.
  96.  
  97. Return value    If  successful, the  exec...  functions  do not  return. On
  98.                 error, the exec... functions return -1, and errno is set to
  99.                 one of the following:
  100.                         E2BIG   Argument list too long
  101.                         EACCES  Permission denied
  102.                         EMFILE  Too many open files
  103.                         ENOENT  Path or file name not found
  104.                         ENOEXEC Exec format error
  105.                         ENOMEM  Not enough core
  106.  
  107. *--------------------------------------------------------------------------*/
  108. int execvpe(char *pathP, char *argv[], char *envV[])
  109. {
  110.         return(_LoadProg(_exec, pathP, argv, envV, 1));
  111. }
  112.  
  113.