Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>spawnlpe() execute program using arg list, path, environment</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
spawnlpe()               Execute Program Using Arg List, PATH, Environment

 #include   <process.h>
 #include   <stdio.h>

 int        spawnlpe(modeflag,pathname,arg0,arg1...,argn,NULL,envp);
 int        modeflag;                    Execution mode for parent process
 char       *pathname;                   Path name of file to be executed
 char       *arg0,*arg1,...,*argn;       List of pointers to argument
 char       *envp[];                     Array of pointers to environment
                                         settings

    spawnlpe() operates identically to spawnle(), with one exception:  If
    'pathname' is not found as described in spawnle(), then spawnlpe()
    will use the DOS PATH to continue the search for pathname.  With that
    single exception, the two functions are identical; see spawnle() for
    a complete description.

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

    The following statements transfer execution to the child process
    "child.exe" and pass it the three arguments "child", "arg1", and
    "arg2".  "child.exe" can be in the current directory or any PATH
    directory.  If "child.exe" is found, the PATH environment variable is
    set to "C:\\TEST" for the child process.  The exit status of the
    child is printed upon return.

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

    char *env[] = {"PATH=C:\\TEST", NULL};

    main()
    {
        int result;

        result = spawnlpe(P_WAIT,"child.exe","child","arg1","arg2",NULL,env);
        if (result != -1)
            printf("exit status of child.exe = %d\n", result);
        else {
            if (errno == ENOENT) {
                printf("child.exe not found in current directory,\n");
                printf("  or in any PATH directory.\n");
            } else if (errno == ENOMEM)
                printf("not enough memory to execute child.exe\n");
            else
                printf("error #%d trying to spawn child.exe\n", errno);
        }
    }

See Also: spawnle() spawn...() exec...()

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