Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun %run/process (specification &key input output error (wait nil))
- "Runs the command-string with args as arguments and input and output streams."
- (let* ((external-process
- (system:run-program (first specification) (flatten (rest specification)) :wait wait))
- (instance
- (make-instance 'process-state
- :external-process external-process
- :input input
- :output output
- :error error)))
- (with-slots (piper-threads) instance
- (setf piper-threads nil)
- (unless (or (null input) (eql input :stream))
- (push (make-thread
- #'(lambda ()
- (handler-case (copy-stream input (system:process-input external-process))
- (stream-error (c) t))
- (close (system:process-input external-process)))
- :name "org.lispos.clash:piper-input")
- piper-threads))
- (unless (or (null output) (eql output :stream))
- (push (make-thread
- #'(lambda ()
- (handler-case (copy-stream (system:process-output external-process) output)
- (stream-error (c) t)))
- :name "org.lispos.clash:piper-output")
- piper-threads))
- (unless (or (null error) (eql error :stream))
- (push (make-thread
- #'(lambda ()
- (handler-case (copy-stream (system:process-error external-process) error)
- (stream-error (c) t)))
- :name "org.lispos.clash:piper-error")
- piper-threads))
- (when wait
- (loop :for thread :in piper-threads :do (bordeaux-threads:join-thread thread))
- (setf piper-threads nil)))
- instance))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement