SimpleExpect 關鍵字可讓您指定服務傳送的正常回應。回應甚至可以是二進位(即隱形 ASCII 字元)回應。若您明確知道(或大致知道)正常回應的內容,即可編寫簡易的正常回應字串供比對之用。

此關鍵字可讓您彈性接受可變回應,並只找出重要資訊。若需要更大的彈性,最好使用 Expect 關鍵字提供的規則運算式語法。

SimpleExpect 指令碼語法是 SimpleExpect=Response ,這裡的回應指服務應該傳回的一連串字元。下表列出的關鍵字可比對邏輯和萬用字元,進而比較回應的每個位元組,同時展開逸出碼。

命令選項:

關鍵字

說明

\x##

二進位值( 十六進位 格式),例如 \x00 是 Null

.

比對任何字元

\%

「%」字元

\.

. 」字元

\\

「\」字元

註: 比對回應時,只能使用您在 Expect 字串中指定的字元數。正常回應必須以這些字元開頭。系統會忽略所有尾隨的其他字元。

例 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