Chapter 3
REDIRECTING COMMANDS
MS-DOS
assumes
that
command input comes from
the
keyboard
and
output goes to
the
screen. However, you
can
redirect
input
so
it
comes from a file
and
output
so
it
goes to a file or a line
printer.
In addition, you
can
create
pipes
that
let one command's
output
become another's
input.
Input
and
Output
To
redirect
input
so
it
comes from a file, use a less-than
sign
«)
in
your command. For example:
s 0 r t <n a me s
(ENTER
I
sorts
the
information
in
the
file Names
and
displays
the
sorted
output.
To
redirect
the
output
of
the
DIR
command so
it
goes to a file,
use a
greater-than
sign
(»
in
your command. For example:
dir
>myfiles
[ENTERI
sends a
directory
listing
to
the
file Myfiles
in
the
current
direc-
tory.
If
Myfiles does not already exist, MS-DOS
creates
it
and
stores
the
listing
in
it.
If
Myfiles does exist, MS-DOS overwrites
the
old
information
with
the
new information.
Append.
To
add your
output
to
the
end of
an
existing file, use
two
greater-than
signs. For example:
di
r
»myf
lies
I
ENTER
I
appends your
directory
listing
to
the
file Myfiles
in
the
current
directory.
If
Myfiles does not exist, MS-DOS
creates
it. Here is
an
example
in
which both
the
input
and
output
are
redirected:
sort
<names
>list1
(ENTER)
This
command
sorts
the
information
in
the
file Names
and
sends
the
sorted
output
to
the
file
Listl
in
the
current
directory.
19