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

Last change on this file since 40277 was 40277, checked in by svnwiki, 2 months ago

Anonymous wiki edit for IP [78.85.5.18]: revert to 0.1

File size: 3.2 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* sh
19* libtcl
20* libexpect
21
22'''Note''': Windows is not supported.
23
24=== Installing
25
26==== Debian-based system
27
281. Install the dependencies
29
30 apt install tcl-dev tcl-expect-dev
31
322. Tell the compiler where the Tcl header files are located by setting the CSC_OPTIONS environment variable
33
34 CSC_OPTIONS="-I/usr/include/tcl"
35
363. Install this egg
37
38 chicken-install tcl-expect
39
40==== Arch-based system
41
421. Install the dependencies
43
44 pacman -S expect
45
462. Determine the Expect version
47
48 expect -version
49
503. Create a symlink
51
52 ln -s /usr/lib/expect<version>/libexpect<version>.so /usr/lib/libexpect.so
53
54Where <version> is the number from the previous step
55
564. Install this egg
57
58 chicken-install tcl-expect
59
60=== Documentation
61
62<procedure>(call-with-process-io cmd proc)</procedure>
63
64Forks a new process and executes {{cmd}} via Bourne shell then call {{proc}} which should be a procedure of three arguments: the input, output, and PID of the sub-process.
65
66'''Note''': The input and output ports will not be closed if {{proc}} raises an error
67
68While it is possible to use {{read-line}} to read information from a process spawned by {{call-with-process-io}}, more convenient function are provided.
69
70<procedure>(expect in-port pattern)</procedure>
71
72The function waits until the output from a process matches the pattern, a specified time period has passed, or an EOF is seen.
73The first argument to the function is an in-port the second argument is a Tcl glob-style string pattern.
74
75Returns one of the following values
76* ok
77* eof
78* timeout
79* fullbuffer
80
81<procedure>(set-timeout secs)</procedure>
82
83Sets timeout for {{expect}} function. The default timeout period is 10 seconds. A value of -1 disables a timeout from occurring. A value of 0 causes the {{expect}} function to return immediately.
84
85=== Example
86
87<enscript highlight="scheme">
88(import (prefix tcl-expect #:expect) (chicken io))
89
90(expect:call-with-process-io "bc"
91                             (lambda (in out pid)
92                              (expect:expect in "`warranty'")
93                              (display "20+12\n" out)
94                              (read-line in)
95                              (read-line in)
96                              (read-line in)
97                              (display (read-line in))))
98</enscript>
99
100=== Changelog
101
102* 0.1 Initial release
103
104=== License
105
106Copyright 2021 Aydar Zarifullin.
107
108This program is free software: you can redistribute it and/or modify
109it under the terms of the GNU General Public License as published by
110the Free Software Foundation, either version 3 of the License, or
111(at your option) any later version.
112
113This program is distributed in the hope that it will be useful, but
114WITHOUT ANY WARRANTY; without even the implied warranty of
115MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
116General Public License for more details.
117
118A full copy of the GPL license can be found at
119<http://www.gnu.org/licenses/>.
Note: See TracBrowser for help on using the repository browser.