Created
March 31, 2017 01:44
-
-
Save fukamachi/46ac200115f1b6129a5f917668529264 to your computer and use it in GitHub Desktop.
external-program to stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#+sbcl | |
(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) | |
#+win32 | |
(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* | |
:status-hook | |
(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