Now that you know a little something
about basic commands and programs, let's move on to
integrating them with files and other commands.
Redirecting
The standard forms of input and output
for most commands are from the keyboard and monitor. However, with
redirection, we can change where the commands get their input and
put their output. More specifically, we can change them to point to
a file or device. For example, instead of the dir command
printing its output to the screen, you can redirect it to a file.
You create a redirect using the "<" and
">" symbols. The "<" is used for
redirecting input and the ">" is for redirecting
output. Below is what the syntax looks like.
syntax ---
C:\WINDOWS\Desktop> command > file-or-device
example ---
C:\WINDOWS\Desktop> dir > dirlist.txt
Keep in mind that redirection is used only in
conjunction with files and devices. So what type of devices can
you use? The only one of concern to us is the prn device. This
represents the printer. Using this, you can redirect a program that normally
outputs to the screen to output to the printer. That's a pretty cool trick if you need a quick hard
copy of a file. For example, lets say you have a list of people you're including
in your plans for world domination in a file called myworld.txt, and you're
in hurry and need a quick print out of this file to show someone. Below is what
you'd type.
C:\WINDOWS\Desktop> type myworld.txt > prn
There's one more thing we forgot to
mention: the nul object. This is what you'd use if you wanted
the command to throw away the output. For example, try typing dir > nul
and hit enter. You shouldn't see anything. That's because it redirects it to nothing,
a null object.
Piping
Pipes are kind of like
redirections except that they redirect input and output between two different programs
or commands instead of files and devices. They work like a real pipe in that you
can string together multiple programs into one long pipe that you can then send data through.
Each program in the pipe operates on
the data and passes along to the next program. To construct a pipe, we use the "|"
symbol between the programs we want to join. Below is an example of piping the
dir command to the more filter.
C:\WINDOWS\Desktop> dir | more
The more filter
takes input and displays it a page at a time. If you try out the above example, you
should see the directory listing pause at every screen full. Another widely
used filter is sort. This filter takes the input and outputs it
in alphabetical order. For example, lets say you want the names on your world domination file to
appear in alphabetical order a page at a time. Below is what you would write.
C:\WINDOWS\Desktop> type myworld.txt | sort | more
Now lets say you wanted to print out
that same file in alphabetical order. Below is what you'd write.
C:\WINDOWS\Desktop> type myworld.txt | sort > prn
It's all that easy. As you can see,
redirection and piping can be very useful when used properly. If you'd like to learn how
to use DOS FTP, check out our DOS FTP walk-through.
Head on to:
Introduction to DOS
Basic DOS Commands
Redirecting And Piping
Back to Tutorial Menu
Back to Webmaster Main Page
Back To HTML Stuff Main Page