Table 51: Environment Commands (continued)
DescriptionCommand
Checks a string against a regular expressionenv.regexpMatch(string)
Extracts a string from a larger stringenv.getRegexpMatch(string)
Capturing Output of Commands
Macro language commands can start and stop the capture of JUNOSe command
output and save the results.
The env.startCommandResults command starts JUNOSe output capture and flushes
any existing capture buffer. The capture stops when directed by a stopcommand or
when the buffer maximum of 5,242,880 (5MB) characters is reached. The command
output in the buffer is stored as normally seen on the terminal output. A <CR> ends
a line of buffer data.
The env.stopCommandResults command stops JUNOSe output captures. The
env.getResults command obtains one line of output from the capture buffer.
The env.startCommandResults, env.stopCommandResults, and env.getResults
commands apply to one CLI session. There is no effect on CLI sessions other than
the CLI session running the macro.
The env.getResults command gets the next line of the capture buffer. Each call gets
the next line of the capture buffer. The command returns the first line the first time
it is called after a capture start (env.startCommandResults). It resets the next line it
returns by passing a line number argument. An argument of 0 or 1 returns the first
line.
For example:
<# env.startCommandResults #>
show version
<# env.stopCommandResults #>
! possibly other JUNOSe commands
<# while something is true #>
<# outputLine := env.getResults #>
. . .
<# endwhile #>
Adding Regular Expression Matching to Macros
Use the following syntax to check a string against a regular expression:
env.regexpMatch(stringToMatch, someRegularExpression)
For example, the string outputLine is checked to determine whether it starts with
the value System:
476 â– Writing Macros
JUNOSe 11.1.x System Basics Configuration Guide