<http://www.netikka.net/tsneti/info/tscmd002.htm>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sun 2-May-2010 11:25:29

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

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.
  1. 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
  2. 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.


For more on the environment settings see item #173.

References/Comments: (If a Google message link fails try the links within the brackets.)
  Google Groups May 1 2007, 3:28 am [M]
  How To Manage Environment Variables in Windows XP
  Environment Variables in Windows XP