Reference number: CH000738
Preventing a MS-DOS window from automatically
closing in Windows.
Question:
Preventing a MS-DOS window from automatically closing in
Windows.
Additional information:
By default, new versions of Windows, with any type of MS-DOS
program, batch file, or other file, will automatically close the
window. Unfortunately, if that MS-DOS command or program outputs or
displays any information that the user needs to read, they will be
unable to read it because it closes too fast.
- If you're running into the problem of not being able to get
a MS-DOS window to close after running a command or batch file,
see document CH000320.
Answer:This issue can be resolved by doing any of the below
recommendations.
Open a MS-DOS window
If you're running a MS-DOS command or program from within Windows,
try opening a MS-DOS prompt and executing the command or program
from within MS-DOS.
Change the path of the command in the shortcut
Microsoft Windows 2000 and Windows XP users can execute the
command or file through CMD.EXE using the /K option. This will
open a command window and then execute the command or program;
after the command or program has completed, the computer will
remain at the command prompt. To do this, follow the below steps.
- Create a shortcut to your MS-DOS program or command.
Additional information about creating a Windows shortcut can
be found on document CH000739.
- Once a shortcut has been created, right-click the shortcut
and click Properties.
- In the Properties window, change the Target location to
contain the CMD.EXE command with the /K switch as shown in the
below example.
Before
"C:\My programs\test.bat"
After
C:\WINNT\system32\CMD.EXE /K
"C:\My programs\test.bat"
Additional information about the CMD command can be found on our
CMD
command page.
Add a pause statement to a batch file
Finally, it is important to realize
that the window will not close if Microsoft Windows believes the
program is still running. If you're creating your own batch file
and wish for the batch file to remain open, one trick is to add
PAUSE to the end of your batch file, which will prompt the user to
press any key; until the user presses any key, the window will not
close automatically.
|
|
| Resolved | Were you able to locate the answer to your questions? |
|
|