Muokkaa

Jaa


.foreach

The .foreach token parses the output of one or more debugger commands and uses each value in this output as the input to one or more additional commands.

.foreach [Options] ( Variable  { InCommands } ) { OutCommands } 

.foreach [Options] /s ( Variable  "InString" ) { OutCommands } 

.foreach [Options] /f ( Variable  "InFile" ) { OutCommands } 

Syntax Elements

Options Can be any combination of the following options:

/pS InitialSkipNumber
Causes some initial tokens to be skipped. InitialSkipNumber specifies the number of output tokens that will not be passed to the specified OutCommands.

/ps SkipNumber
Causes tokens to be skipped repeatedly each time a command is processed. After each time a token is passed to the specified OutCommands, a number of tokens equal to the value of SkipNumber will be ignored.

Variable
Specifies a variable name. This variable will be used to hold the output from each command in the InCommands string; you can reference Variable by name in the parameters passed to the OutCommands. Any alphanumeric string can be used, although using a string that can also pass for a valid hexadecimal number or debugger command is not recommended. If the name used for Variable happens to match an existing global variable, local variable, or alias, their values will not be affected by the .foreach command.

InCommands
Specifies one or more commands whose output will be parsed; the resulting tokens will be passed to OutCommands. The output from InCommands is not displayed.

InString
Used with /s. Specifies a string that will be parsed; the resulting tokens will be passed to OutCommands.

InFile
Used with /f. Specifies a text file that will be parsed; the resulting tokens will be passed to OutCommands. The file name InFile must be enclosed in quotation marks.

OutCommands
Specifies one or more commands which will be executed for each token. Whenever the Variable string occurs it will be replaced by the current token.

Note   When the string Variable appears within OutCommands, it must be surrounded by spaces. If it is adjacent to any other text -- even a parenthesis -- it will not be replaced by the current token value, unless you use the ${ } (Alias Interpreter) token.

Additional Information

For information about other control flow tokens and their use in debugger command programs, see Using Debugger Command Programs.

Remarks

When the output from InCommands, the InString string, or the InFile file is parsed, any number of spaces, tabs, or carriage returns is treated as a single delimiter. Each of the resulting pieces of text is used to replace Variable when it appears within OutCommands.

Here is an example of a .foreach statement that uses the dds command on each token found in the file myfile.txt:

0:000> .foreach /f ( place "g:\myfile.txt") { dds place } 

The /pS and /ps flags can be used to pass only certain tokens to the specified OutCommands. For example, the following statement will skip the first two tokens in the myfile.txt file and then pass the third to dds. After each token that is passed, it will skip four tokens. The result is that dds will be used with the 3rd, 8th, 13th, 18th, and 23rd tokens, and so on:

0:000> .foreach /pS 2 /ps 4 /f ( place "g:\myfile.txt") { dds place } 

For more examples that use the .foreach token, see Debugger Command Program Examples.