If you follow the flow of the script,
you should expect the following output:
Griff
Asa
Etch
because the goto command has caused the printing of Ox to be skipped. The
label can appear before or after the goto line in a batch file, and you can
have multiple goto commands and multiple labels.
Command-Line Parameters
Suppose you executed a batch file called Demo.bat by typing the following
at the Command Prompt:
Demo file1.txt file2.txt
Both file1.txt and file2.txt are command-line parameters and are automatically
stored in two variables, %1 and %2, respectively, when the batch file is run.
560 | Chapter 9: Scripting and Automation
The implication is that you could run a batch file that would then act with
the filenames or options that have been passed to it. ???How to Use Command-
Line Parameters,??? earlier in this chapter, shows how command-line
parameters are used with WSH scripts.
The following two-line example uses command-line parameters and the FC
utility to compare two text files. A similar example using the Windows
Script Host, shown in ???Make Building Blocks with Subroutines and Functions,???
takes 22 lines to accomplish approximately the same task:
fc %1 %2 >c:\windows\temp\output.txt
notepad c:\windows\temp\output.txt
Save this batch file as compare.bat, and execute it like this:
compare c:\windows\tips.txt c:\windows\faq.txt
which will compare the two files, tips.txt and faq.txt (both located in your
Windows folder), save the output to a temporary file, and then display the
output by opening the file in Notepad.
Pages:
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780