How To Close Console Window When MS-DOS Application Completes

Last reviewed: November 12, 1996
Article ID: Q152682
The information in this article applies to:
  • Microsoft Win32 Software Development Kit for Microsoft Windows 95, version 4.0

SUMMARY

In Windows 95, the default behavior of the operating system is to keep the console window of an MS-DOS application open if it has displayed text in the window. This provides users with an opportunity to read any messages that may have been displayed in the window before the window is closed. To close a window in this state, you must click the close button (that is, "X") on the window caption or Close on the System menu.

In some instances, however, the user's needs may require that the console window close automatically. The solution is to programmatically remove all the displayed text of an MS-DOS application thereby allowing the console window to close automatically.

MORE INFORMATION

The displayed text of an MS-DOS application can be removed by adding the application to the following .bat file:

   @echo off
   <DOS app>
   @cls

Then launch this .bat file instead of the original application. The first line, @echo off, prevents .bat file commands from being displayed in the window. Once the MS-DOS application has completed, the cls command clears any text that may have been sent to the Console window. Thus, because no displayed text has been left in the Console window, the Console window closes after the .bat file has completed.


KBCategory: kbprg kbusage kbhowto
KBSubcategory: Bsecon
Additional reference words:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 12, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.