ID Number: Q69989
5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a
MS-DOS | OS/2
Summary:
In Microsoft C versions 5.1, 6.0, 6.0a, 6.0ax,and C/C++ version 7.0, the
spawnlp() function may be used to shell out to the MS-DOS or OS/2
command prompt from within a C program by spawning a copy of the MS-DOS
or OS/2 command interpreter. This method is demonstrated in the sample
program below. The P_WAIT mode must be used under MS-DOS and is
recommended under OS/2 as well.
More Information:
The spawnl() function may also be used if a path to the command
interpreter is given explicitly in argument 1 of the parameter list.
See the documentation or online help supplied with your version of the
compiler for more information about the spawn family of functions.
These same functions are also available in QuickC, including versions
2.0, 2.01, 2.5, and 2.51.
Sample Code
-----------
/* Compile options needed: none
*/
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
void main(void)
{
if ( _osmode == DOS_MODE ) /* Running under MS-DOS */
{
printf("Shelling out to DOS, type 'EXIT' to return\n");
spawnlp(P_WAIT, "COMMAND.COM", "COMMAND.COM", NULL);
}
else /* Running under OS/2 */
{
printf("Shelling out to OS/2, type 'EXIT' to return\n");
spawnlp(P_WAIT, "CMD.EXE", "CMD.EXE", NULL);
}
printf("Back from Shell\n");
}
Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00