3 ms·
I do not use cl-launch, but for some tasks at job I wanted to pipe programs, and just wanted to try implementing something myself. The with-pipeline macro creat
by junke 8y ago
I do not use cl-launch, but for some tasks at job I wanted to pipe programs, and just wanted to try implementing something myself. The with-pipeline macro creates temporary fifos to connect programs and threads (random example):
(let ((counter 0))
(with-pipeline ()
(program "ls" "-1la")
(lambda-line (line)
(format t "~x~%" (incf counter (length line))))
(program "sed" "-n" "s/A/_/g ; /__/ p"))
counter)
Outputs and return:
2__8
15399
Macroexpansion:
(catch :pipeline
(block nil
(let* ((#:input%2195 (pipeline::ensure-stream nil :input nil))
(#:output%2196 (pipeline::ensure-stream t :output nil))
(#:error%2197
(pipeline::ensure-stream :output :error #:output%2196)))
(let ((#:g2199 (program "ls" "-1la"))
(#:g2200
(lambda-line (line)
(format t "~x~%" (incf counter (length line)))))
(#:g2201 (program "sed" "-n" "s/a/_/g ; /__/ p")))
(pipeline.pipes:with-pipes% (#:pipes2198 2)
(lastcar
(mapcar #'pipeline.filters:clean
(list
(pipeline.filters:spawn #:g2199 :input #:input%2195 :output
(pipeline.pipes:pipe-out
(svref #:pipes2198 0))
:error #:error%2197 :wait nil)
(pipeline.filters:spawn #:g2200 :input
(pipeline.pipes:pipe-in
(svref #:pipes2198 0))
:output
(pipeline.pipes:pipe-out
(svref #:pipes2198 1))
:error #:error%2197 :wait nil)
(pipeline.filters:spawn #:g2201 :input
(pipeline.pipes:pipe-in
(svref #:pipes2198 1))
:output #:output%2196 :error
#:error%2197 :wait t)))))))))
https://github.com/christophejunke/pipeline https://github.com/christophejunke/pipeline