Site hosted by Angelfire.com: Build your free website today!
Chapter 39: Running DOS Programs and Commands

PreviousChapterContentsGlossaryNext

Running DOS Programs

Once you run a DOS program, you can do your work and then exit. You can also adjust the way it looks on the screen, copy-and-paste material to and from the Windows Clipboard, print, and run batch files.

Starting DOS Programs

You run a DOS program the same way you run a Windows program: by clicking or double-clicking its icon or filename in the Windows Explorer window or the Start menu, or by choosing Start | Run and typing its name into the Run dialog box. For some DOS commands, you can type arguments or switches on the command line after the program name, separated by spaces. An argument provides additional information (for example, the DOS COPY command accepts arguments that tell it what files to copy). A switch specifies a program option and usually consists of a slash (/) and a letter.

You can also type DOS commands at a DOS prompt by selecting Start | All Programs | Accessories | Command Prompt (or by choosing Start | Run and typing cmd). You see the Command Prompt window (Figure 39-1). In this window, you can type DOS commands--such as DIR, CHDIR, MKDIR, and DELETE--as well as run programs. Just type the command (possibly followed by arguments or switches) and press ENTER. The Command Prompt enables you to see the results of your commands, too.

note Windows XP comes with two programs that display a Command Prompt window: Command.exe and Cmd.exe. Command.exe displays a Command Prompt window that cannot handle long filenames (that is, filenames longer than eight characters and extensions longer than three characters). Cmd.exe's window handles filenames the same way that Windows does. There's no reason to use Command.exe rather than Cmd.exe.

If you run a specific program to open the window, the program name appears in the title bar. If you choose the Start | All Programs | Accessories | Command Prompt command, the window is named Command Prompt.

While the vast majority of DOS commands work, not all do, and most will not operate as expected. For a mostly complete list of commands accepted by the Command Prompt, type help and press ENTER.

To get help with a particular DOS command, type the command followed by /?. For example, type copy /? to get help with the DOS COPY command. To stop the help text from scrolling off the top of the Command Prompt window, add | more to the end of the command line, like this:

copy /? | more

tip If you can open a file by clicking or double-clicking it in Windows Explorer, you can open the file from the DOS prompt. Type start followed by a space and the pathname (address) of the file. If the pathname contains spaces, enclose it in double-quotation marks. The Start program opens the file (or folder) using the Windows file association.

Exiting DOS Programs

Every DOS program has its own command to exit. Some use a function key, some use a text command (like "quit" or "exit"), and some use a menu command starting with a slash or another character. You can also force Windows to close a Command Prompt window by clicking the Close button while the program is running. Windows may warn you that closing the program will lose unsaved information, but if you click End Now, Windows stops the program and closes the window anyway.

Adjusting the Screen

Windows normally starts each Command Prompt window as a 25 0xd7 80 character window, choosing a font to make the window fit your screen. You can select a different font from the Command Prompt Properties dialog box's Font tab.

To switch between running in a window and using the full screen, press ALT-ENTER. Once in a full screen, ALT-ENTER is the only way, short of exiting and restarting the program, to return the program to running in a window.

Using the Mouse and Clipboard

Early versions of DOS provided no mouse support at all. Even in later versions, DOS provided only low-level mouse support, leaving it entirely up to each application which (if any) mouse features to provide. As a result, most DOS programs provide no mouse support, so the primary use of the mouse is to cut-and-paste material to the Windows Clipboard.

Using the Windows Clipboard

You can copy material from a Command Prompt window to the Clipboard. To do so, first click the System Menu button (with the C:\ icon) in the upper-left corner of the window and select Edit | Mark from the System menu that appears. Then use the mouse to highlight the area to copy and press ENTER to copy the selected area to the Clipboard.

note DOS programs can place the screen (or the virtual screen emulated in a Command Prompt window) into either text mode (which can display only text) or graphics mode (which can display any pattern of dots, including text). Windows copies the marked area as text if the screen is in text mode and as a bitmap if the screen is in graphics mode. Some programs, such as word processors, often use graphics mode to display text so that they can show font changes. Tell the DOS program to switch back to text mode before copying, to get text on the Clipboard.

Windows lets you paste text from the Clipboard into DOS applications, too. The text is entered as though you had typed it on the keyboard. To paste, select Edit | Paste from the System menu.

Using the Mouse in DOS Programs

In those DOS programs that do provide mouse support, using the mouse in a Command Prompt window can be difficult. Since DOS provides no high-level mouse support, each application displays its own mouse pointer. In some Windows-aware applications, the DOS mouse pointer is synchronized with the Windows mouse pointer, but more often than not, it isn't. In the latter case, the best solution usually is to press ALT-ENTER to switch to full-screen mode, so there's no Windows mouse pointer at all.

Printing from DOS Programs

Windows provides very limited support for printing from DOS programs. It offers a pass-through scheme that receives output from DOS programs and sends it directly to the printer. DOS programs have no access to Windows printer drivers, so each DOS application must have its own driver for any printer that it prints to.

Windows intercepts the DOS output and spools the output as it does printer output from Windows applications (that is, Windows stores the output and then sends it to the printer). This provides more flexibility in printer management and avoids the possibility that a DOS program will interfere with an active print job from another program.

Determining the Printer Port

DOS programs identify your printer according to the port to which the printer is attached (LPT1, LPT2, LPT3, COM1, COM2, COM3, or COM4). To find out what port a printer is attached to, follow these steps:

  1. Select Start | Printers and Faxes (or Start | Control Panel | Printers and Other Hardware | Printers and Faxes) to open the Printers and Faxes window.
  2. Right-click the desired printer and select Properties to open the printer's Properties dialog box.
  3. Click the Ports tab to see a list of the ports, and look down the list for the first one whose check box is selected. If the dialog box has no Ports tab, look on all the tabs--the contents of the dialog box depend on the printer driver.
  4. Click OK to close the printer Properties dialog box.

Printing to a Network Printer

DOS programs can also print to network printers. Windows captures the output from a simulated printer port and then spools the printer output through the network in the same way that printer output is spooled from Windows programs.

caution All printers are not created equal. Their capabilities depend both on the printer hardware and on the printer driver software. You may notice anywhere from subtle to enormous differences between the printer-related dialog boxes you see in this book and those you see on your computer. If you don't see a feature we mention here, your printer probably doesn't have it. Check your printer's manual to prevent yourself from wasting a lot of time on something that will simply not work.

To print from a DOS program to a network printer, follow these steps:

  1. Determine the pathname of the printer by displaying its Properties dialog box (as described in the previous section). If you see a Ports tab, look on that tab at the bottom of the list of ports for the pathname (you may need to drag the Port column divider to the right to make the entire name visible). The pathname is in the format \\computername\printername, where computername is the computer's name on the LAN, and printername is the printer's share name.
  2. Close the printer's Properties dialog box.
  3. Choose Start | All Programs | Accessories | Command Prompt to open a Command Prompt window.
  4. Type the following command and press ENTER. Replace n with the LPT number you want to use (if you already have a printer on LPT1, use LPT2), and \\computername\printername with the printer's pathname.

net use lptn: \\computername\printername /persistent:yes
  1. Now you can print from your DOS program to the LPT port you specified. When you are finished printing, type this command in the Command Prompt window:

net use lptn: /delete

When you print from a DOS program to a spooled printer, either local or networked, Windows has no reliable way to tell when the DOS program is finished printing. If your program doesn't print anything for several seconds, Windows assumes that it's finished. This occasionally causes problems when an application prints part of a report, computes for a while, and then resumes printing, because Windows can interpret the pause in printing as the end of the print job. If this is a problem, use a locally connected printer and do not configure the printer to spool DOS print jobs.

Running Batch Files

DOS provides batch files, which are text files that contain a sequence of commands to be run as though they were typed at the DOS prompt. Batch files have the filename extension .bat. Windows treats a batch file as a DOS program and opens a Command Prompt window to run the batch file and any programs that the batch file runs. Since the Windows version of DOS lets you run any DOS or Windows program from the DOS prompt, you can use batch files as a low-budget scripting language, listing a sequence of programs you want to run.

For example, you can use a batch file as quick-and-dirty backup scheme for making copies of a few files on a Zip or other removable disk. Write a batch file that copies the files from their current location to the Zip disk. Then use the Windows Scheduled Tasks program to run the batch file every night, and remember to leave a Zip disk in your Zip drive.

PreviousChapterContentsGlossaryNext