I recently heard from a customer who felt that Windows was beyond all control and understanding. He dreamed of switching to Linux in a brighter world. This act of desperation wouldn’t be necessary because buried inside every Windows computer is a DOS computer waiting to get out. It is possible to exert a degree of control comparable to a Unix system. I realized that some of our software users may not be aware of this capability. In this article and following ones, I will show how to apply DOS capabilities. Your first reaction might be: “Why do I want features from a 1980s operating system? Is this just a hacker thing?” My contention is that there are a lot of practical tasks you can accomplish with DOS, particularly if you do intensive number crunching with programs like ours. When you combine the interactive features of Windows with the direct control of a terminal environment, you have a very powerful system.
Finding the Terminal
In the Start menu, click on Run. Type “cmd” in the dialog box and click “OK”. The terminal opens in a small window. Your are probably thinking, “What is that ugly excrescence on my screen? Make it go away!” The gray letters on a black background are dispiriting. I suspect this is Microsoft’s attempt to discourage you from going any further. Around the time of Windows 98, the company even threatened to eliminate the Terminal, but they had to back down in the face of a general outcry. Perhaps the Terminal reminds them of their humble beginnings.
To start, let’s make the Terminal more appealing. Right-click on the top of the screen and bring up Properties. In the Font tab, pick your favorite fixed-width font. My boomer eyes prefer Lucinda Console 12. Go to Layout and set the Height under Window size to 50. Finally, under Colors set the Screen background to white and pick a nice text color. When you click OK, choose the option to apply the settings to all future instances. Close the current terminal by clicking the X box in the upper right-hand corner.
You’re more likely to use the terminal if it’s easy to start. Move the mouse cursor into your desktop area, right-click and choose New/Shortcut. In the first dialog, just enter “cmd”. In the second, type in “Terminal”. Now you have a direct shortcut to the Terminal on your desktop.
Lists of DOS commands
You will find a wealth of resources by entering “dos commands” in your search engine. Here’s a great site that lists the commands available under the latest version of Windows:
IMPORTANT WARNING. DOS gives you unlimited power for good or evil. Don’t try a command without a complete understanding of what it does. Commands like “del *.*”, “erase *.*” and “format” will cause disaster.
Doing something useful
Let’s start by creating a handy utility that records a text listing of the files in a directory. You can then copy and paste the results into a document. To begin, we need a place to store the batch files that we will create. Start a Terminal and enter “cd \” to go to the root directory. Enter “mkdir batch” to create a new directory.
To make things easier in the future, we want to be sure that “\batch” is on the path so that our utilities will run if we type the command from anywhere on the disk. (The following instructions apply to Windows XP. You may need administrative privileges for Vista.) From the Control Panel, bring up System. Go to the Advanced tab and push the button for Environmental Variables. In the System Variables menu, scroll down to Path and push the Edit button. Go to the end of the string in Variable value and carefully add “;c:\batch” (don’t include the quotation marks). In your terminal window, type “path” to see the current state of the environmental variable. If the new content isn’t there, check that it has been included the next time you boot.
We are going to create a batch file with a text editor. If you don’t have a good editor, the post Using the ConTEXT text editor describes how to get ConTEXT for free. Start a new file in ConTEXT and add the single line
dir %1 > %1\filelist.txt
Save the file in “\batch” with the name “filelist.bat”. To test the program, enter
in your terminal. Then, open the file “\batch\filelist.txt” in ConTEXT. It should have content that looks like this
Volume in drive C has no label. Volume Serial Number is 49DE-1E06 Directory of C:\batch 04/20/2008 03:44 PM <DIR> . 04/20/2008 03:44 PM <DIR> .. 04/20/2008 03:44 PM 24 filelist.bat 18 File(s) 39,614,888 bytes 2 Dir(s) 108,373,622,784 bytes free
Now we can talk about how the single line of the batch file works. The “dir” command lists the directory contents. The parameter “%1” is expanded to the command line parameter: “\batch”. The “>” symbol redirects the text output to the file “\batch\filelist.txt”. If you don’t include a parameter when you type the command, the batch file writes a list for the current directory in the current directory.
To finish, let’s make the batch command even more useful by calling it directly from a text editor. In ConTEXT, click on Options/Environmental options and then choose the Execute keys tab. If you followed the directions for adding a spell checker in Using the ConTEXT text editor, you should have a group that is activated for the suffixes “txt”, “html” and “tex”. Activate the group and use the Edit key to add the “bat” suffix. Activate the F12 key and enter “filelist” under Execute and “%p” under Parameters. Now, if you are editing one of the file types, just press F12 and “filelist.txt” will appear in the directory of the file that you are currently editing. You can then open the file and grab any information necessary.
We’ve made considerable progress. If you’ve followed along, your computer is set up to use batch files effectively. In the next posting of this series, I’ll discuss how to run our programs from the Terminal and the advantages of doing this. We’ll also download a useful command-prompt program that will let your computer talk to you.