
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>spawnvp() execute program using arg array, path</b>
[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
spawnvp() Execute Program Using Arg Array, PATH
#include <process.h>
int spawnvp(modeflag,pathname,argv);
int modeflag; execution mode for parent process
char *pathname; path name of file to be executed
char *argv[]; Array of pointers to arguments
spawnvp() operates exactly like spawnv(), with one exception: If
'pathname' is not found as described in spawnv(), then spawnvp() uses
the current directory, followed by the DOS PATH to continue the
search for the path name. Otherwise, the two functions are
identical; see spawnv() for a complete description.
Portability: MS-DOS only.
-------------------------------- 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. The exit status of the child is printed upon return.
#include <process.h> /* for 'spawnvp' and 'P_WAIT' */
#include <stdio.h> /* for 'printf' and 'NULL' */
#include <errno.h> /* for 'errno', 'ENOENT' and 'ENOMEM' */
char *args[] = {"child", "arg1", "arg2", NULL};
main()
{
int result;
result = spawnvp(P_WAIT, "child.exe", args);
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: spawnv() spawn...() exec...()
Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson