How to Shell Out to System Prompt from Within a C ProgramLast reviewed: July 17, 1997Article ID: Q69989 |
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50 1.51 1.52
MS-DOS | OS/2 | WINDOWSkbprg The information in this article applies to:
SUMMARYIn Microsoft C, 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 INFORMATIONThe 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.
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");} NOTE: For more information on spawning applications in Win32 operating systems, refer to Knowledge Base article Q125213.
|
Additional reference words: kbinf 6.00 6.00a 6.00ax 7.00 1.00 1.50 spawning
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |