This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
2} On Windows XP how do you stop the script files from closing?
If one runs a .cmd script file by clicking the icon of the script,
the window will close after the processing is completed.
Occasionally this may not be what the user wants.
Method 1: To keep the window open to see the results one can use:
:: The body of the script with whatever task.
:: Then
pause
This will produce
Press any key to continue . . .
The window will then close when a key is pressed.
You also might notice that some of my scripts
included in this collection have the concluding line
if not defined cmdbox if defined PauseIfFromDesktop pause
The purpose of such a line is to prevent a script from immediately
closing on completion if called (clicked) from the desktop. This
allows you to view the results. However, this requires some special
arrangements.
- I have defined a PauseIfFromDesktop variable into my
default environment:
- Right click: My Computer
- Choose Properties
- Choose Advanced
- Click "Environment Variables"
- For User variables click New
- Define PauseIfFromDesktop true
- See the "set cmdbox=true" spot in item #3.
Method 2: There is a more generic solution. Put as the very last
line of your script
cmd
The window will remain open as is (was) familiar from the Win3.x/95/98/Me
dosbox, and it will allow you to give further commands. To finally
close the window, type "exit". See
item #3
for utilizing the "cmd" line in customizing a command line window to
your liking.