Microsoft KB Archive/69989

{|
 * width="100%"|

How to Shell Out to System Prompt from Within a C Program

 * }

Q69989

-

The information in this article applies to:


 * The C Run-Time (CRT), included with:
 * Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax
 * Microsoft C for OS/2, versions 6.0, and 6.0a
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 1.5, 1.51, 1.52

-

SUMMARY
In 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 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.

Sample Code
/* Compile options needed: none


 * 1) include 
 * 2) include 
 * 3) include 

void main(void) {  if ( _osmode == DOS_MODE )   /* Running under MS-DOS */ {      printf(&quot;Shelling out to DOS, type 'EXIT' to return\n&quot;); spawnlp(P_WAIT, &quot;COMMAND.COM&quot;, &quot;COMMAND.COM&quot;, NULL); }  else   /* Running under OS/2 */ {      printf(&quot;Shelling out to OS/2, type 'EXIT' to return\n&quot;); spawnlp(P_WAIT, &quot;CMD.EXE&quot;, &quot;CMD.EXE&quot;, NULL); }  printf(&quot;Back from Shell\n&quot;); } NOTE: For more information on spawning applications in Win32 operating systems, refer to Knowledge Base article Q125213.

Additional query words: kbinf 6.00 6.00a 6.00ax 7.00 1.00 1.50 spawning exec

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCRT