May 17th, 2005
Occasionally, you might want to run a batch file and leave the command console window open, so that you can enter other commands in the directory where it left off.
You can do this as follows.
Note: In this example, I'm using a batch file to open a context-sensitive help topic, using the
keyHH.exe program.
1. Create your batch file as normal.
e.g.
@echo off
REM Change to the imuser directory
REM within the current directory (i.e. the directory
REM in which this batch file lives)
cd %cd%\imuser
REM Use keyHH.exe to open a help topic
REM using its map ID
@echo on
keyHH.exe -myHelp -#mapid 1001 "imuser.chm>$global_ContextWindow"
Notes:
- I'd forgotten all about using REM for comments and switching echo on and off. It takes me way back to the 1980s when I started programming by writing programs in Mallard BASIC.
-
cd %cd%\imuser changes the current directory to the
imuser subdirectory within the directory in which you place the batch file.
2. Save the batch file, giving it an appropriate name (with a
.bat file name extension) and putting it in an appropriate directory. In this example, I'm calling the file
open-context-topic.bat.
For convenience, I want to have a file in the
D:\CVS_local_copy\helpFiles\src directory that I can double-click to open a help topic in the child directory
imuser.
3. Create another batch file. You'll use this one to open a non-closing console window from which you'll call the first batch file.
e.g.
@echo off
REM Open a console window (using -k so that it gets left open)
REM and call the batch file for opening a context-sensitive
REM help topic.
@echo on
cmd /k "open-context-topic.bat"
4. Save this batch file in the same directory as the first one (or somewhere else if you want, but you'll need to add a path to the file name, which makes it less transportable).
You can now open Windows Explorer, browse to the directory where you saved the batch files, double-click the second batch file and the command in the first file will execute and leave the console window open so that you can use it.
In my case I use this to test help topics, so I copy and paste the previous command, changing the map ID number to the one for the topic I want to test. I can then leave the window open and just use the up cursor key to get the previous command each time, edit to change the map ID as required, and press Enter. It's a big time saver.
To make the batch file more accessible, you can drag a shortcut to the second batch file onto the Windows Explorer Links toolbar, the desktop, your Favorites, etc.
Potentially similar posts