Win Command of the Command Line Interface - Testing and Usage (
Page 5 of 7 )
Testing the Application
At some point, you can start testing your console application. Of course, that means providing command line switches. The Command Line Arguments field of the Debug page of the project Properties dialog box shown in Figure 3 is where you supply command line arguments. You only supply the arguments as shown in the figure and not the name of the application.
ADVERTISEMENT
Figure 3: Set the command line switches for your application before you debug it.
Make sure you supply the arguments in the order you expect to see them in the output. In addition, the /FD command line argument requires two switches, such as /FD "dd/MM/yyyy". Note that you can find the standard formatting strings at http://msdn.microsoft.com/en-us/library/az4se3k1.aspx and the custom formatting strings at http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx. When you run this application in debug mode and supply the /LD /LT command line arguments shown in Figure 3, you see the output shown in Figure 4.
Figure 4: Typical output of the ShowDT application.
Real World Usage
I use this utility in a number of ways. For example, if I plan to keep a directory listing for a while, I’ll start by typing ShowDT /LD /LT > MyDir.TXT and pressing Enter. Notice the use of the single redirection operator. This forces the system to overwrite MyDir.TXT and create a new file. The next step is to type Dir *.* >> MyDir.TXT and press Enter. Notice the use of the double redirection operator this time. This operator appends the new content to the MyDir.TXT file. What you get as output is a file like the one shown in Figure 5. Now, when I view that directory listing again, I know precisely when I created it.
Figure 5: Time stamping a directory listing lets you know when you last checked it.
There are other uses for the ShowDT utility. For example, I use the following command to create a directory listing of all of the files in my System32 folder that contain the keyword Microsoft in them: FindStr /m “Microsoft” > MyDir.TXT (the /m command line switch says to display only the filenames). This process can take a while, so I work on something else while I wait. I then time stamp the file by typing ShowDT /LD /LT >> MyDir.TXT and pressing Enter. The next week I do the same thing using a different filename. So, now I have two files that should contain the same list of files. All I have to do to look for changes is rely on the FC command to find them for me. Theoretically, all I should see is the timestamp at the end of the file.
You can also use ShowDT to display the time and/or date as part of a batch file. An expanded version of this utility could track how much time it takes to complete a task. ShowDT is actually quite helpful.
Creating the Windows Forms Example
Many developers associate the command line with console applications. Actually, a lot more applications than you might think work just fine at the command line—many of them have a GUI interface. For example, create a file named MyHello.txt and type something in it. Now, open a command line, type Notepad MyHello.txt, and press Enter. Notepad opens the file for editing. Even though they aren’t properly documented, Notepad even provides command line switches. Type Notepad /p MyHello.txt, press Enter, and Notepad will send the text file directly to the default printer. GUI applications do provide a command line interface in many situations and so can yours.
As with a console application, you need to support the /? command line switch when working with a Windows forms application. The major difference is that a GUI application may not always show output at the command prompt. A good example of this is Notepad, which uses the command line arguments to load a file. In some cases, such as when using the /p command line switch, you don’t even see Notepad because it starts up only long enough to send the file to the printer. However, nothing stops you from sending output to the command line either.