Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>execl() execute program using argument list</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 execl()                 Execute Program Using Argument List

 #include <process.h>                    Required for declarations only

 int execl(pathname,arg0,arg1,...,argn,NULL);
 char       *pathname;                   Path name of file to be executed
 char       *arg0,*arg1,...,*argn;       List of pointers to arguments

    execl() loads and executes a new child process, which is placed in
    the memory currently occupied by the calling process. There must be
    enough available memory to load and execute the child process.

    'pathname' specifies the file name of the child process.  If
    'pathname' has a file name extension, then only that file is searched
    for. If 'pathname' ends with a period (.), then 'pathname' without an
    extension is searched for.  If 'pathname' has no extension and does
    not end with a period, then execl() searches for 'pathname' and, if
    it is not found, appends ".COM" and searches again. If that is not
    found, it appends ".EXE" and searches again.

     'arg0', 'arg1',...'argn' are passed to the child process as command-
    line parameters.  'argn' must be followed by a NULL pointer, which
    terminates the list of arguments. 'arg0' must not be NULL, and is
    usually set to 'pathname'.

    The maximum length for all strings forming the argument list passed
    to the child process is 128 bytes.  This includes "n" (for 0 to n
    arguments) space characters (required to separate the arguments) but
    does not include the null ('\0') terminating character.

    Returns:    If execl() is successful, it does not return to the
                calling process. (See the spawn...() routines for a
                similar function that can return to the calling process).
                If an error occurs, execl() returns -1 to the calling
                process. On error, 'errno' (defined in <stdlib.h>) is set
                to one of the following values (defined in <errno.h>):

                    E2BIG       Argument list or environment list too big.
                                  (List > 128 bytes, or environment > 32k)
                    EACCES      Locking or sharing violation on file.
                                  (MS-DOS 3.0 and later)
                    EMFILE      Too many files open.
                    ENOENT      File or path not found.
                    ENOEXEC     File not executable.
                    ENOMEM      Not enough memory.

      Notes:    Any file open when an exec call is made remains open in
                the child process.  This includes 'stdin','stdout',
                'stderr', 'stdaux', and 'stdprn'.

                The child process acquires the environment of the calling
                process.

                Translation modes of open files are not preserved by
                execl().  Use setmode() in the child process to set the
                desired translation modes.

                'environ' (defined in <stdlib.h>) points to a list of
                environment settings for the current process.

                See the spawn...() routines for similar though more
                flexible functions that can return to the calling
                program.

    Caution:    The file pointers to open buffered files are not always
                preserved correctly.  The information in the buffer may
                be lost.

                Signal settings are not preserved.  They are reset to the
                default in the child process.

 Portability:   Xenix, OS/2, or MS-DOS 3.0 or higher.

   ----------------------------- Example -------------------------------

    The following statements transfer execution to the child process
    "child.exe" and pass it the three arguments "child", "arg1",
    and"arg2":

           #include <process.h>    /* for 'execl' */
           #include <stdio.h>      /* for 'printf' and 'NULL' */
           #include <stdlib.h>     /* for 'errno' */
           #include <errno.h>      /* for 'ENOENT' and 'ENOMEM' */

           main()
           {
               execl("child.exe", "child", "arg1", "arg2", NULL);
               /* only get here on an exec error */
               if (errno == ENOENT)
                   printf("child.exe not found in current directory\n");
               else if (errno == ENOMEM)
                   printf("not enough memory to execute child.exe\n");
               else
                   printf("  error #%d trying to exec child.exe\n", errno);
           }



See Also: execle() execv() execve() execvpe() spawnl()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson