Reading user input from a terminal
Execution phase and CLI event synchronization waiting mode
result1_value, result2_description = ops.terminal.read(maxLen=512, timeout=30, vty=None)
Parameter |
Description |
Value |
---|---|---|
maxLen |
Indicates the maximum length of the entered character string. |
The value is an integer that ranges from 1 to 512. The default value is 512. |
timeout |
Indicates the timeout interval. |
The value is an integer that ranges from 0 to 60, in seconds. The default value is 30 seconds. |
vty |
Indicates a user terminal. |
The value is None or the VTY channel name obtained using ops.environment.get("_cli_vty"). |
The result1_value and result2_description in the API prototype indicate return values.
None: indicates that waiting process times out or a user presses Ctrl+C.
Empty string: indicates that a user presses Enter directly.
1: indicates that an error is returned. The reason of the error is described by the second return value.
Other string: indicates user input (only when the second return value is success).
The second return value is as follows:
success: indicates that user input from a terminal is read successfully.
Other string: indicates the reason why user input from a terminal failed to be read.
The command line event must be subscribed, and you must wait until the script execution is complete after the command is executed. That is, the subscribed event must be defined through ops.cli.subscribe, and sync must be set to True.
This API enables you to obtain the information entered by users from a terminal and use it in scripts. A maximum of 10 ops.terminal.read APIs are supported in one script.
When a subscription event is matched, you can read user input from the terminal.
value, descri_str = ops.terminal.read(maxLen=512, timeout=30, vty=None)