Experts Exchange connects you with the people and services you need so you can get back to work.
ret = _spawnlp(_P_NOWAIT, "C:\\Program Files\\MyApp\\bpd.bat");
Open in new window
If either cmdname or arg0 is an empty string or a null pointer, these functions generate an invalid parameter exception
The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!
The _spawnl, _spawnle, _spawnlp, and _spawnlpe calls are typically used in cases where the number of arguments is known in advance. The arg0 argument is usually a pointer to cmdname. The arguments arg1 through argn are pointers to the character strings forming the new argument list. Following argn, there must be a NULL pointer to mark the end of the argument list.
ret = _spawnlp(_P_NOWAIT, "C:\\Program Files\\MyApp\\bpd.bat", "bpd", NULL);
char* pCmd = "\"C:\\Program Files\\MyApp\\bpd.bat\""; // add quotes
ret = _spawnlp(_P_NOWAIT, pCmd, pCmd, NULL);
The cmdname argument specifies the file that is executed as the new process and can specify a full path (from the root), a partial path (from the current working directory), or just a file name. If cmdname does not have a file name extension or does not end with a period (.), the _spawn function first tries the .com file name extension and then the .exe file name extension, the .bat file name extension, and finally the .cmd file name extension.
If cmdname has a file name extension, only that extension is used. If cmdname ends with a period, the _spawn call searches for cmdname with no file name extension. The _spawnlp, _spawnlpe, _spawnvp, and _spawnvpe functions search for cmdname (using the same procedures) in the directories specified by the PATH environment variable.
If cmdname contains a drive specifier or any slashes (that is, if it is a relative path), the _spawn call searches only for the specified file; no path searching is done.
printf("Running ps with spawnlp\n");
pid = _spawnlp( _P_NOWAIT, "ps", "ps", NULL );
// Suspend our execution until the child has terminated.
// obtain termination code upon completion.
_cwait(&tstat, pid, WAIT_CHILD);
printf("Child process %d terminated with code %d.\n", pid, tstat);
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $25.00.
Premium members get this course for $174.99.
Premium members get this course for $24.99.
Premium members get this course for $95.20.
Premium members get this course for $159.20.
Premium members get this course for $151.20.
Premium members get this course for $122.40.