source: project/wiki/eggref/5/tcl-expect @ 40180

Last change on this file since 40180 was 40180, checked in by svnwiki, 3 months ago

Anonymous wiki edit for IP [78.85.48.72]: documentation added

File size: 3.4 KB
Line 
1== tcl-expect
2
3Chicken scheme binding to libexpect
4
5Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications.
6
7=== Author
8
9Aydar Zarifullin
10
11=== Repository
12
13[[https://github.com/iZarif/ckn-expect|https://github.com/iZarif/ckn-expect]]
14
15=== Dependencies
16
17* Linux
18* libtcl
19* libexpect
20
21'''Note''': Windows is not supported.
22
23=== Installing
24
25==== Debian-based system
26
271. Install the dependencies
28
29 apt install tcl-dev tcl-expect-dev
30
312. Tell the compiler where the Tcl header files are located by setting the CSC_OPTIONS environment variable
32
33 CSC_OPTIONS="-I/usr/include/tcl"
34
353. Install this egg
36
37 chicken-install tcl-expect
38
39==== Arch-based system
40
411. Install the dependencies
42
43 pacman -S expect
44
452. Determine the Expect version
46
47 expect -version
48
493. Create a symlink
50
51 ln -s /usr/lib/expect<version>/libexpect<version>.so /usr/lib/libexpect.so
52
53Where <version> is the number from the previous step
54
554. Install this egg
56
57 chicken-install tcl-expect
58
59=== Documentation
60
61<procedure>(call-with-process-io cmd proc)</procedure>
62
63Forks a new process and executes {{cmd}} then call {{proc}} which should be a procedure of three arguments: the input, output, and PID of the sub-process.
64
65'''Note''': The input and output ports will not be closed if {{proc}} raises an error
66
67While it is possible to use {{read-line}} to read information from a process spawned by {{call-with-process-io}}, more convenient function are provided.
68
69<procedure>(expect in-port pattern [timeout 10])</procedure>
70
71The function waits until the output from a process matches the pattern, a specified time period has passed, or an EOF is seen.
72The first argument to the function is an in-port the second argument is a Tcl glob-style string pattern the optional third argument sets timeout. The default timeout period is 10 seconds. A value of -1 disables a timeout from occurring. A value of 0 causes the function to return immediately.
73
74Returns one of the following values
75* ok
76* eof
77* timeout
78* fullbuffer
79
80=== Example
81
82<enscript highlight="scheme">
83(import (prefix tcl-expect #:expect) (chicken io))
84
85(expect:call-with-process-io "bc"
86                             (lambda (in out pid)
87                              (expect:expect in "`warranty'")
88                              (display "20+12\n" out)
89                              (read-line in)
90                              (read-line in)
91                              (read-line in)
92                              (display (read-line in))))
93</enscript>
94
95=== Changelog
96
97* 0.1 Initial release
98* 0.2
99** set-timeout function has been removed
100** spawn function no longer uses 'sh' to execute commands
101** expect function now takes an optional third argument - timeout
102
103=== License
104
105Copyright 2021 Aydar Zarifullin.
106
107This program is free software: you can redistribute it and/or modify
108it under the terms of the GNU General Public License as published by
109the Free Software Foundation, either version 3 of the License, or
110(at your option) any later version.
111
112This program is distributed in the hope that it will be useful, but
113WITHOUT ANY WARRANTY; without even the implied warranty of
114MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
115General Public License for more details.
116
117A full copy of the GPL license can be found at
118<http://www.gnu.org/licenses/>.
Note: See TracBrowser for help on using the repository browser.