Forum Discussion
ichalis_37981
Dec 13, 2011Historic F5 Account
The EVAL command
Hi all,
I am testing the eval command and want to generate an error if my input script contains an error. My test code is as follows:
set cmd "if { \[HTTP::uri\] starts_with \"/h...
hoolio
Cirrostratus
Dec 13, 2011Hi,
The catch command already executes the wrapped expression. So you could use [catch { eval $cmd } myresult]. Wrapping eval $cmd in square braces executes the output of eval again resulting in the invalid command name. Here's a version which should work and not require escaping the characters in the command:
when HTTP_REQUEST {
set cmd {if { [HTTP:uri] starts_with "/hello" }{ log local0.alert "match!!!" }}
if { [catch {
eval $cmd
} myresult] != 0 } {
log local0. "My rule failed: $myresult, \$cmd: $cmd"
} else {
log local0. "My rule succeeded: $myresult, \$cmd: $cmd"
}
}
That said, why do you want to use catch for this? catch handles errors, but it's not too likely that you'd get a runtime error with that anyhow.
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects