mirror of
https://github.com/hymkor/lispect.git
synced 2026-08-28 04:46:59 -04:00
3.4 KiB
3.4 KiB
Lispect
- A text-terminal automation tool similar to expect(1) of UNIX and Linux
- It runs on Windows 10 and later, and Linux
- The script is written in the subset of ISLisp (gmnlisp)
(if (equal (getenv "OS") "Windows_NT")
(spawn "cmd.exe" "/k" "set PROMPT=$$$S")
(spawn "bash"))
(defglobal ctrlc (create-string 1 (convert 3 <character>)))
(block main
(while t
(expect*
("xxx"
(send ctrlc)
(expect "$ ")
(sendln "exit")
(return-from main nil)
)
(("yyy" "zzz")
(send ctrlc)
(expect "$ ")
(sendln 'interval 200 "echo test")
)
(10 ; timeout second
(send ctrlc)
(expect "$ ")
(sendln "exit")
(return-from main nil)
)
)
)
)
Functions and variables
Parameters enclosed in curly braces {...} are optional and can be omitted.
(send {'interval MS} "STRING")- Send STRING to the terminal
- Specify the
'interval MSoption to make the program wait MS milliseconds before outputting each character
(sendln {'interval MS} "STRING")- send STRING and Enter-key to the terminal
(expect {'timeout SEC} "STRING-0" "STRING-1" ...)- Wait until STRINGs are found on the terminal
- When STRING-n is found on the terminal, it will return n
- If a timeout occurs after SEC seconds have elapsed, it returns -1
(expect* ("STRING-0" COMMANDS-0...) ("STRING-1"...)... (SEC COMMANDS-FOR-TIMEOUT...))- When STRING-n is found on the terminal, COMMANDS-n will be executed
- After SEC seconds have elapsed, COMMANDS-FOR-TIMEOUT will be executed
(spawn "COMMANDNAME" "ARG-1" ...)- Start the executable file
args- List of command line arguments
Other functions are defined on ISLisp
Technologies used
- Creating a Pseudoconsole session - Windows Console | Microsoft Learn
- aymanbagabas/go-pty: Cross platform Go Pty interface
- hymkor/gmnlisp: gmnlisp - the subset of ISLisp
Comparison with Expect-lua
| Expect-lua | Lispect | |
|---|---|---|
| Started | 2017 | 2024 |
| Script | Lua (GophaLua) | ISLisp (gmnlisp) |
| Windows 7/8 | Supported | Not Supported |
| Windows 10/11 | Supported | Supported |
| Linux | Not Supported | Supported |
| Mechanisms | ReadConsoleOutputW | PseudoConsole |
| Read Misses | Possible1 | Unlikely |
| Stdout Redirection | Unavailable | Available |
| Status | Stable | Work in Progress |
-
When the output is too excessive, there might be some dropped data ↩︎