Hi,

Consider I'd like to run programs using ptys and interact with them.
So I started considering such code snippet:

;;; open a shell and ask for directory listing
(defvar proc (sb-ext:run-program "sh" nil
                                                      :search t :input :stream :output :stream :wait nil))
(format (sb-ext:process-input proc) "ls -l /tmp~%echo '###'~%")
(force-output (sb-ext:process-input proc))
(loop
          :with output = (sb-ext:process-output proc)
          :for line = (read-line output nil 'eof)
          :until (or (eq line 'eof) (string= line "###"))
          :do (print line))

That works fine, but as intended, it uses pipes as IPC.
How to do this if I want to use pty ? I tried using :pty :stream, but this didn't work. I can see the process is indeed spawned with pty allocated, but I can't communicate with it while the process is still alive:

CL-USER> (defvar proc (sb-ext:run-program "sh" nil
                                                      :search t :input :stream :output :stream :pty :stream :wait nil))
PROC
CL-USER> proc
#<SB-IMPL::PROCESS 5195 :RUNNING>
CL-USER> (sb-ext:process-input proc)
#<SB-SYS:FD-STREAM for "descriptor 10" {B9A6671}>
CL-USER> (sb-ext:process-output proc)
#<SB-SYS:FD-STREAM for "descriptor 12" {B9A66F9}>
CL-USER> (format (sb-ext:process-input proc) "ls -l /tmp~%echo '###'~%")
NIL
;;; now flush output:
CL-USER> (force-output (sb-ext:process-input proc))
Couldn't write to #<SB-SYS:FD-STREAM for "descriptor 10" {B9A6671}>:
  Broken pipe
   [Condition of type SB-INT:SIMPLE-STREAM-ERROR]
; Evaluation aborted on #<SB-INT:SIMPLE-STREAM-ERROR {AD6B5D9}>.
CL-USER>

and back to shell:
$ ls -l /proc/5195/fd
lrwx------ 1 nicolas users 64 2011-05-01 11:01 0 -> /dev/pts/3
lrwx------ 1 nicolas users 64 2011-05-01 11:05 1 -> /dev/pts/3
lrwx------ 1 nicolas users 64 2011-05-01 11:05 2 -> /dev/pts/3
lrwx------ 1 nicolas users 64 2011-05-01 11:05 255 -> /dev/pts/3

Obviously, I am missing something, but looking at the sbcl documentation didn't help me that much.
Could someone explain ?
Thanks.


:Nicolas