febooti softwarehome of febooti softwarefebooti software

MS-DOS command redirection operators

Batch files
homenewsproductsdownloadsorderingsupportcontacts
show Quick Links
hide Quick LinksQuick Links: Command line email home | Online help | Commands | Batch files | FAQ | Buy now | Download


The two most commonly used redirection operators used are the output redirection operator and the input redirection operator. The output redirection operator > is used to send the command output to somewhere other than the screen. A text document would be an example. An example would be wanting to put the results of the DIR command into a text document. Let us name the text file dir.txt

C:\>DIR > dir.txt
Type text Copy text

When this command is entered either at a Windows DOS prompt or in a batch file you do not see the directory listing like you would if you had simply entered the DIR command. Instead, a file is created and in this case the file is named dir.txt. This can be used to capture practically any command.

Run this file several times and notice the changes. One might think that each time you run this program (DIR > dir.txt), each result of the DIR command gets saved to that dir.txt file. Well, each time you run that program you will erase the preceding contents and save the new DIR listing information. What if we wanted to create a type of log that would append and save each new occurrence of the above program? We can use what is called the append redirection operator. This is done by adding another greater than sign.

C:\>DIR >> dir.txt
Type text Copy text

Next we have the input redirection operator. The input redirection operator is used to send the contents of a file to a DOS command (normally the contents of keyboard input get sent to the DOS command). You have probably already guessed that, since the output redirection operator is >, the input redirection operator will be a <. That would be a correct guess.

An example of when you would want to do this would be if you have a text file that is too large for the Windows command prompt screen. You can enter the following command sequence:

C:\>MORE < dir.txt
Type text Copy text

If your DIR listing was very long than you would be prompted to Press any key to continue . . . after a screen-full amount of data was displayed. Once you pressed (almost) any key you would see the next screen-full amount of data. If it was short than the MORE command will simply display the text as if you typed the TYPE command. The TYPE command is used to display the contents of a file. You do not need to use a redirection operator to use the TYPE command.

C:\>TYPE dir.txt
Type text Copy text

This will produce the contents of dir.txt to screen.

The next command we will learn is the DOS piping command. The pipe | can usually be inserted to the command prompt by holding down the shift key and pressing the key to the direct left of the backspace key. DOS piping is a technique that combines both the output and input redirection operators. We can capture the output of one command and send it as the input to another command. Example:

C:\>DIR | MORE
Type text Copy text

In this example the pipe command captures the output of the dir command and sends it as input to the MORE command which will display one screen-full of results at a time.

You will come to find that batch scripting really does have a great amount of power and has wonderful uses. However, there will be a time when you will find that batch will have just not quite enough power. That is the price we pay for having such a nice and easy to learn tool at our hands.


Previous DOS batch commandDOS batch command 11 of 11
Return to Origin
Next DOS batch command



Look closer
febooti Command line email client: send mail from Windows command line (MS-DOS prompt)
febooti ieZoom toolbar - zoom IE web site pages
febooti fileTweak - change file date, time and attributes


How to?
How to use -LOG command with DOS mail
Command line email utility - Tips & Tricks
How to debug Command line email


Links
febooti software affiliate program
Link to us!
Links


febooti softwarehome of febooti software
back to top
Copyright © 2001-2006 febooti software. All rights reserved.
Copyright © 2001-2007 febooti software. All rights reserved. Last Updated: April 23, 2007