Thursday, December 11, 2008

Is cmd.exe and command.com the same ?

Basically when we glance at the black screen thrown at us by Windows boxes when command.com or cmd.exe is executed, they look the same. But cmd.exe which is the command prompt in Windows 2000/XP/NT is far superior in performance and the power that it packs than command.com.

The most important difference is the added feature by which cmd.exe stores the history of all commands executed in a command session. It is a nifty add-on, which can be of a great blessing when you are forced to work a non-GUI way extensively. You can track back to the very first command issued by you in a session using the up-arrow key on your keyboard and can traverse through the whole array of commands used in a session using the arrow keys.

In this article which we will take a journey through some of the features offered by cmd.exe

Utilizing the Switches

First let’s have a look at the various command line switches available to ‘cmd.exe’.

  • /C Switch :

Think of a situation where, you need to execute a command just after loading ‘cmd.exe’, you can go for this command line switch. This switch loads a session of ‘cmd.exe’ into memory, executes the command specified after /C and terminates the cmd session.

Ex : cmd /C dir

This creates a new command session and executes the command dir in the new command session. After execution the new session terminates.

  • /K Switch :

This switch is the same like /C, but after completion of the command the session is not terminated.

Ex : cmd /K date

This creates a new command session and executes the date command, the session is not terminated after completion of the command.

  • /Q Switch :

    This switch is handy if you want to turn off the echoing property of command line. After Launching a command line session with /Q switch ensures that all commands from batch files are run without them getting echoed on the screen.

    Ex : cmd /Q

  • /A Switch :


The /A switch of cmd.exe ensures that all redirected or piped outputs from the current session is in ANSI.

Ex: cmd /A

Now this instance of command prompt will ensure that all redirected outputs are of ANSI in nature. To test this run a dir command and redirect the output to some file.

  • /U Switch:

    This ensures that all outputs from a command session is redirected as Unicode.

    Ex: cmd /U

    Now run the same test that we did at the cmd /A example. If we compare the two files generated from the /A and /U examples, we can find that the file generated by the /U session is a bit more large as it is encoded in Unicode.

  • /T switch :

    This switch lets you add color to your black and white command line world. The switch is used in a format like cmd /T: forecolor/backcolor.

    Ex : cmd /T:F0

    The above command will make the current command session in to a window with white background and black foreground color.
There are a whole lot of other command line switches also for cmd.exe. We will be dealing with them in the next issue of this article.
Page 2

Some Functional Shortcuts

cmd.exe offers a set of nice shortcut’s, which can be used extensively for making the working in command mode a lot easier. In this section we will look into some of these shortcuts in command prompt.

F1 Key


This functional key echo’s the last executed command from cmd.exe’s buffer on to the screen, one character at a time. If the last command is ‘echo hello’ then pressing F1 key three times will dump the characters ‘ech’ at the command prompt.

F2 Key


This nifty functional key can be used to get a portion of the last command up to a specific character back on to the command line. The below given example will get the point clear for you.

Fig 1

Fig 2

In Fig 1 we are executing a lengthy command. Suppose you need to get a part of the command upto the character ‘s’ in ‘devtools’ back to the command prompt. For this press F2 key and a new small window (Fig 2) will popup, prompting you to ‘Enter char to copy up to:’ Now press ‘s’ and a part of the last executed command up to the character ‘s’ will be prompted back (Fig 3) on the command prompt.

Fig 3

F3 Key

This key dumps the last executed command on to the command prompt.

F4 Key


This key can be utilized for deleting a range of characters form current entry on the command prompt. Try out the below given sample snippet.

In Fig 4 we are inputting a simple echo command.

Fig 4

Now if we need to remove all characters from ‘H’ in ‘Hello’ to ‘B’ in ‘Bay’ from command prompt, then position the cursor under ‘H’ and press F4. A new popup as in Fig 5 will be shown, and there press ‘B’ as input and voila all the characters from ‘H’ in hello to ‘B’ will be removed from command prompt.


Page 3

F5 Key

F5 Let’s the user to loop through a history of commands which were executed in a command session. Any one of the previously executed commands can be accessed by repeatedly pressing F5 key.

F7 Key

This key presents the user with a menu like popup (Fig 6) from which all the last executed commands can be accessed. User’s can navigate from one command to other in this popup using Arrow keys.

Fig 6

The numbers given on the left hand side of each command represents the position of the command in the command history buffer. This number can be utilized for direct access to the command for which the number stands.

F9 Key

This functional key gives the user direct access to the command items stored at the command history of a command prompt. In Fig 6 command number 20 stands for ‘echo Hello World From Wisdom Bay’. Now if you want to get that command back on the command prompt all you have to do is press F9 (a popup will be shown as in Fig 7), input 20 and press enter.
Fig 7

This will result in the prompting of the ‘echo Hello World From Wisdom Bay’ as the current command at the command window.

This concludes the first part of my article on ‘cmd.exe’. Will be back next time with more demystifying thoughts on this topic.

http://www.wisdombay.com/articles/article00001.htm

No comments:

Post a Comment

Custom Search
Powered By Blogger