source: project/wiki/eggref/4/pty @ 27045

Last change on this file since 27045 was 27045, checked in by sjamaan, 9 years ago

pty docs: Fix unbalanced parens and point out that gui-get-password should be provided somewhere else

File size: 4.4 KB
Line 
1== pty
2
3Easy Pseudo-Terminal Interface
4     
5=== Author
6
7Alex Shinn
8
9=== Documentation
10
11PTY allows you to run sub-processes in pseudo-terminals
12and access their input and output from the controlling
13program as regular Chicken ports.  This is useful for
14a variety of purposes, such as:
15
16* Run a remote session via ssh or rlogin using a user-supplied password.
17* Automate some or all of a terminal game or program (such as nethack or vi).
18* Run fsck, answering "yes" or "no" based on pre-determined criteria.
19* Implement an xterm program.
20
21In general these cannot be done with regular sub-process ports.
22
23==== High-Level Interface
24
25<procedure>(call-with-pty-process-io command proc [name [width [height]]])</procedure>
26
27Call and return the result of {{proc}} which should be a procedure of
28three arguments: the input, output and PID of the sub-process
29{{command}} running in a new PTY. Ensures the sub-process is
30terminated on completion.
31
32{{name}}, {{width}} and {{height}} are optional settings for the new
33PTY.
34
35{{command}} may optionally be a list specifying the arglist to the
36sub-process, or a single string which is split on whitespace.
37
38The ports generated only block the current thread, and {{char-ready?}}
39only returns #t if some input is already available.  The eof-object is
40returned only when the sub-process terminates.
41
42'''NOTE:''' Prior to login of, and after completion of the
43sub-process, anything written to the output port will pass directly
44through to the input port, which is almost certainly not what you
45want.  To avoid premature writes, you should read once first.  To
46avoid writing after the process has completed, don't write after
47you've read a single eof-object, or alternately you can check manually
48with {{process-alive?}}.
49
50<procedure>(with-pty-process-io command proc [name [width [height]]])</procedure>
51
52As above, except current input and output ports are bound to the
53output and input of {{command}} respectively, and {{proc}} only takes
54one argument, the PID.
55
56=== Low-Level Interface
57
58<procedure>(open-pty-process command [name [width [height]]])</procedure>
59<procedure>(open-pty [name [width [height]]])</procedure>
60<procedure>(login-tty fd)</procedure>
61<procedure>(process-alive? pid)</procedure>
62<procedure>(fcntl-ref fd)</procedure>
63<procedure>(fcntl-set! fd arg)</procedure>
64<procedure>(file-select-one fd)</procedure>
65<procedure>(file-read/maybe fd buf len)</procedure>
66<procedure>(open-file-io/non-blocking fd [process-alive? (-> boolean)])</procedure>
67
68=== Example
69
70<enscript highlight="scheme">
71(use pty)
72
73(call-with-pty-process-io "ssh myfirewall"
74  (lambda (in out pid)
75    (peek-char in)
76    (display (gui-get-password) out) ;; You'll need to implement this!
77    (newline out)
78    (read-line in)
79    (display "dhclient 2>/dev/null && echo OK || echo FAIL\n" out)
80    (unless (equal? "OK" (read-line in))
81      (error "couldn't launch dhclient"))))
82</enscript>
83
84=== Changelog
85
86* 1.3 setup script fixes (felix)
87* 1.1 MacOS X compile [Kon Lovett]
88* 1.0 Initial release
89
90=== License
91
92  Copyright (c) 2006 Alex Shinn
93  All rights reserved.
94 
95  Redistribution and use in source and binary forms, with or without
96  modification, are permitted provided that the following conditions
97  are met:
98  1. Redistributions of source code must retain the above copyright
99     notice, this list of conditions and the following disclaimer.
100  2. Redistributions in binary form must reproduce the above copyright
101     notice, this list of conditions and the following disclaimer in the
102     documentation and/or other materials provided with the distribution.
103  3. The name of the author may not be used to endorse or promote products
104     derived from this software without specific prior written permission.
105 
106  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
107  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
108  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
109  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
110  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
111  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
112  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
113  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
114  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
115  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
Note: See TracBrowser for help on using the repository browser.