Team LiB
Previous Section Next Section

Some Final Notes

This section contains some final "odds and ends" tips that may make your programming life a little easier.

All Command-Line Environments Aren't Created Equal!

The various different versions of Windows—Windows 2000, Windows XP, and Windows Server 2003—implement command prompts a bit differently. Therefore, rules regarding how "true" command prompts behave won't necessarily apply to your particular version of Windows. You'll have to experiment a bit with your particular "flavor" of command prompt to find out what does or doesn't work well.

Here are some of our experiences with using Windows 2000 and Windows XP specifically.

Capturing Program Output to a File

You can capture program output and compilation error messages to files via the file redirection symbol, >.

For example, running our Success.exe program via the command

C:\> Success > somefile

captures what would normally appear as output to the screen (e.g., the Hooray! It works! message from our earlier example) in a text file instead; this is known as redirecting standard output.

To capture error messages to a file when compiling, the same file redirection symbol should do the trick:


C:\> csc Success.cs > somefile

thus taking advantage of a technique known as standard error redirection.

Note?/td>

Note that the technique used for redirecting standard output differed from the technique used for redirecting the standard error stream with older versions of Windows.

File Names and the Command Prompt Window

While a command prompt does indeed allow us to manipulate complex Windows file/directory names, such as those that contain white space, we sometimes have to do something extra for this to work out properly.

For example, "C:\Program Files" is the name of a standard directory on most Windows systems; note the blank space between "Program" and "Files" in this directory name. If we were to try to look at the contents of this folder while in the command prompt window via the following command:

C:\> dir Program Files

the following error message would be displayed:

File Not Found

This situation arises because the system interprets what we typed as two commands rolled into one: dir Program and dir Files.

The solution is to surround the multiword directory name in double quotes:

C:\ dir "Program Files"

The system now knows that we're referring to a single, multiple-word directory name.


Team LiB
Previous Section Next Section