diff options
author | Rutger van Beusekom <rutger.van.beusekom@verum.com> | 2020-03-02 10:38:57 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2020-05-16 22:36:19 +0200 |
commit | 786fbcd32764813969bd1a211d0003cf4a161b65 (patch) | |
tree | a76ea62308a6fadd9404dd9b6110e481b76b84f8 /doc | |
parent | 2c07a32ad85d6fce8a0e09bb457e7ff1885b4615 (diff) | |
download | guile-786fbcd32764813969bd1a211d0003cf4a161b65.tar.gz |
popen: Add 'pipeline' procedure.
* libguile/posix.c (scm_open_process): Remove.
(scm_piped_process): Add to replace open_process.
* module/ice-9/popen.scm (pipe->fdes): Add to convert pipe pair to fdes pair.
(open-process): Add open-process for backwards compatibility.
(pipeline): Add to implement a pipeline using piped-process.
* doc/ref/posix.texi (Pipes): Document it.
* test-suite/tests/popen.test ("open-process")
("piped-process", "piped-process: with output")
("pipeline"): New tests.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/ref/posix.texi | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 2c85f803a..e5d63c7b3 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -2370,6 +2370,34 @@ processes, and a system-wide limit on the number of pipes, so pipes should be closed explicitly when no longer needed, rather than letting the garbage collector pick them up at some later time. +@findex pipeline +@deffn {Scheme Procedure} pipeline commands +Execute a @code{pipeline} of @var{commands} --- where each command is a +list of a program and its arguments as strings --- returning an input +port to the end of the pipeline, an output port to the beginning of the +pipeline and a list of PIDs of the processes executing the @var{commands}. + +@example +(let ((commands '(("git" "ls-files") + ("tar" "-cf-" "-T-") + ("sha1sum" "-"))) + (pipe-fail? (lambda (pid) + (not + (zero? + (status:exit-val + (cdr + (waitpid pid)))))))) + (receive (from to pids) (pipeline commands) + (let* ((sha1 (read-delimited " " from)) + (index (list-index pipe-fail? (reverse pids)))) + (close to) + (close from) + (if (not index) sha1 + (string-append "pipeline failed in command: " + (string-join (list-ref commands index))))))) +@result{} "52f99d234503fca8c84ef94b1005a3a28d8b3bc1" +@end example +@end deffn @node Networking @subsection Networking |