No Matter What You Use, the "FOR" command has enough power that it can solve ninety percent
of all your problems. Really! Reading the entry on the FOR command
should take you about a half hour. While reading, you'll confirm your
suspicion (around the time you are reading the difference between
single quotes, double quotes, and back quotes) that Bill Gates is mad.
The stuff on the "set" command and the "parameters" will be
much easier to understand. Those two (along with "for") will solve 99%
of all your batch problems. Just don't bother trying to memorize it.
Just read all of it so you know what it can do. You can always look up
the details later when you need to actually use it.
The |<>@ symbols
Use the "pipe" character "|" (the vertical bar) to send the output from
a command into the input of another command. For example:
type test.txt | program.exe
That would send the output of the "type" command into the input of the
"program.exe" command. The "type" command in this case would be putting
out the contents of the file "test.txt". The "program.exe" would (in
theory) accept that as it's input instead of accepting input from the
keyboard. Use redirection characters ">" and "<" to send output
between files and programs. Notice the difference? The pipe sends stuff
between two PROGRAMS. Redirection is between a program and a FILE. The
redirection arrow lets you know what direction the data is flowing. For
example:
program.exe
> test.txt
would take the output of "program.exe" and put it in the file
"test.txt" INSTEAD of displaying it on the screen. The data flows out
of the program "program.exe" and into the file "test.txt". On the other
hand:
program.exe
< test.txt
Would cause "program.exe" to use "test.txt" as it's input INSTEAD of
taking input from the keyboard. The data flows out of the file
"test.txt" into the program "program.exe". So these two lines are
different ways of doing the same thing:
type test.txt
| program.exe
program.exe
< test.txt
They both end up telling "program.exe" to use the data in "test.txt" for
input instead of using the keyboard. The difference between ">" and
">>" is that ">"
normally creates a new file, replacing what was there, while ">>"
just adds to the end of the file (If the file doesn't already exist, it
will be created). You can even use redirection in non-intuitive order
and it still works. For example, these two lines do the same thing:
program.exe
> test.txt
> test.txt
program.exe
Why do it the second way? Sometimes the second way looks neater when
you have lots of program commands going into a single file.
The "@" symbol can be put on the beginning of any command to stop the
command from appearing on the screen. Any output from the program goes
to the screen, but the command itself doesn't. For example, on a "dir"
command, I only want to see a list of files. I do NOT want to see the
command "dir". Normally, you can turn off all screen echoes by
using the "echo off" command. So anything after the "echo off" command
only shows program output. Unfortunately, the echo command still gets
echoed! However, if you put an @ sign in front of the echo command, it
turns off the echo from the echo command. That's why most batch files
start with this:
@echo
off
Lost? Look at the site map.
Bad links? Questions? Send me mail.