Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
external-program to stream
(defun start (commands)
(check-type commands cons)
(multiple-value-bind (inputfd-shell outputfd-shell)
#+win32 (sb-win32::make-named-pipe) #-win32 (sb-posix:pipe)
(multiple-value-bind (inputfd-cl outputfd-cl)
#+win32 (sb-win32::make-named-pipe) #-win32 (sb-posix:pipe)
(setf (sb-win32::inheritable-handle-p inputfd-cl) t
(sb-win32::inheritable-handle-p outputfd-cl) t)
(let ((input (sb-sys:make-fd-stream inputfd-cl :input t :serve-events t))
(output (sb-sys:make-fd-stream outputfd-shell :output t))
(shell-output (sb-sys:make-fd-stream outputfd-cl :output t)))
(values (make-two-way-stream input output)
(external-program:start (first commands) (rest commands)
:input (sb-sys:make-fd-stream inputfd-shell :input t)
:output shell-output
:error *error-output*
(lambda (process)
(when (eq (external-program:process-status process) :exited)
(close shell-output)
(close output)))))))))
#-sbcl (error "Supports only SBCL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.