Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/pty|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. == pty Easy Pseudo-Terminal Interface === Author Alex Shinn === Documentation PTY allows you to run sub-processes in pseudo-terminals and access their input and output from the controlling program as regular Chicken ports. This is useful for a variety of purposes, such as: * Run a remote session via ssh or rlogin using a user-supplied password. * Automate some or all of a terminal game or program (such as nethack or vi). * Run fsck, answering "yes" or "no" based on pre-determined criteria. * Implement an xterm program. In general these cannot be done with regular sub-process ports. ==== High-Level Interface <procedure>(call-with-pty-process-io command proc [name [width [height]]])</procedure> Call and return the result of {{proc}} which should be a procedure of three arguments: the input, output and PID of the sub-process {{command}} running in a new PTY. Ensures the sub-process is terminated on completion. {{name}}, {{width}} and {{height}} are optional settings for the new PTY. {{command}} may optionally be a list specifying the arglist to the sub-process, or a single string which is split on whitespace. The ports generated only block the current thread, and {{char-ready?}} only returns #t if some input is already available. The eof-object is returned only when the sub-process terminates. '''NOTE:''' Prior to login of, and after completion of the sub-process, anything written to the output port will pass directly through to the input port, which is almost certainly not what you want. To avoid premature writes, you should read once first. To avoid writing after the process has completed, don't write after you've read a single eof-object, or alternately you can check manually with {{process-alive?}}. <procedure>(with-pty-process-io command proc [name [width [height]]])</procedure> As above, except current input and output ports are bound to the output and input of {{command}} respectively, and {{proc}} only takes one argument, the PID. === Low-Level Interface <procedure>(open-pty-process command [name [width [height]]])</procedure> <procedure>(open-pty [name [width [height]]])</procedure> <procedure>(login-tty fd)</procedure> <procedure>(process-alive? pid)</procedure> <procedure>(fcntl-ref fd)</procedure> <procedure>(fcntl-set! fd arg)</procedure> <procedure>(file-select-one fd)</procedure> <procedure>(file-read/maybe fd buf len)</procedure> <procedure>(open-file-io/non-blocking fd [process-alive? (-> boolean)])</procedure> === Example <enscript highlight="scheme"> (use pty) (call-with-pty-process-io "ssh myfirewall" (lambda (in out pid) (peek-char in) (display (gui-get-password) out) ;; You'll need to implement this! (newline out) (read-line in) (display "dhclient 2>/dev/null && echo OK || echo FAIL\n" out) (unless (equal? "OK" (read-line in)) (error "couldn't launch dhclient")))) </enscript> === Changelog * 1.3 setup script fixes (felix) * 1.1 MacOS X compile [Kon Lovett] * 1.0 Initial release === License Copyright (c) 2006 Alex Shinn All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 12 to 6?