send standard input with sys:open-pipe
I'm trying to run a program that reads on standard input and then writes the result on standard output. I'm not seeing how to do that in LispWorks (Mac 7.1). I have used sys:open-pipe before, but just to drive an interactive program. Below is my failed attempt - it just hangs.
John DeSoi, Ph.D.
(defun test (&optional (input "Test 123"))
(let ((pipe (sys:open-pipe "cat" :direction :io :element-type 'character :save-exit-status t :use-pty t))
(out-stream (make-string-output-stream :element-type 'character))
(ch nil)
(out "")
(result -1))
(write-line input pipe)
(write-char #\ETX pipe) ;Ctrl-C and also tried Ctrl-D.
(force-output pipe)
(setf result (sys:pipe-exit-status pipe :wait t))
(loop while (setf ch (read-char-no-hang pipe nil nil)) do
(write-char ch out-stream))
(close pipe)
(setf out (get-output-stream-string out-stream))
(values out result)))
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html