Tip
Subject Content

224
Use the command line to redirect input and output

As the computer industry continues to advance, and as users rely more on Windows applications,

users will become less familiar with basic command line concepts. However, certain concepts, such

as input and output redirection, are very useful.



Redirect output

For example, assume you want to display a directory listing with DIR, but you want to save the

results to a text file that you can edit with Notepad to create a batch file or script. You can redirect

the output of the DIR command to a text file with the greater than character [>]:



DIR > Myfile.txt



This command makes DIR redirect the output to Myfile.txt. If the file exists, its contents are

overwritten.



To append the output to the end of the file, rather than overwrite it, use two greater than characters

[>>]:



DIR >> Myfile.txt



Redirect input

Assume you want to sort the contents of a text file and display it to the screen; the SORT command

can take keyboard input, or you can redirect the input from your text file:



SORT < Myfile.txt



You also can combine input and output redirection. This example directs input from Myfile.txt to

the SORT command and directs the output to a new file named Sorted.txt:



SORT < Myfile.txt > Sorted.txt

Page 225 of 237
First Previous Next Last