脚本语法:SimpleExpect 关键词
- Last Updated: May 21, 2026
- 2 minute read
- WhatsUp Gold
- Version 2026
SimpleExpect 关键词可让您指定服务发送的正常回应。响应甚至可以是二进制 (即隐形 ASCII 字符) 回应。若您明确知道 (或大致知道) 正常响应的内容,即可编写简易的正常响应字符串供匹配之用。
此关键词可让您弹性接受可变响应,并只找出重要信息。若需要更大的弹性,最好使用 Expect 关键词提供的正则表达式语法。
SimpleExpect 脚本语法是 SimpleExpect=Response,这里的响应指服务应该返回的一连串字符。下表列出的关键词可匹配逻辑和通配符,进而比较响应的每个字节,同时展开转义码。
命令选项:
关键词 | 描述 |
|---|---|
|
\x## |
二进制值(十六进制格式),例如 \x00 是 Null |
|
。 |
匹配任何字符 |
|
\% |
“%”字符 |
|
\. |
“.”字符 |
|
\\ |
“\”字符 |
示例 1:# # Note: script comments start with a # character## Send=Hello There## Expect a nice response#SimpleExpect=Hi, how are you?
示例 2:# # Send a command followed by CR/LF# Send=Select * from Accounts\r\n## Expect a large response, be we only care to check that first word# received is "Customer"#SimpleExpect=Customer
示例 3:# # Send a binary escape (27) an x y and z and then a nak (21)#Send=\x1B\x15## Expect any byte (we don't care) then an abc and an ack (6)#SimpleExpect=.abc\x06