From 7fede3fd969091355bbf5015bac57b4be2a74144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 16 Apr 2023 19:04:26 +0200 Subject: [PATCH] Extend process IO --- src/util-io.scm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/util-io.scm b/src/util-io.scm index 51ccf58..55a5a87 100644 --- a/src/util-io.scm +++ b/src/util-io.scm @@ -30,6 +30,7 @@ ( read-lines/no-bom get-process-output-lines + get-process-exit+output-lines process-send/recv ) @@ -58,7 +59,7 @@ (cdr lines))))) ;; Very simple shell command wrapper that returns lines produced by - ;; given command. Dangerous - performs no argument escaping! + ;; given command. (define (get-process-output-lines cmd . args) (let-values (((stdout stdin pid stderr) (process* cmd @@ -67,9 +68,22 @@ args)))) (close-output-port stdin) (let ((result (read-lines stdout))) - (let-values (((a b c) (process-wait pid))) + (let-values (((pid exit-ok? exit/signal) (process-wait pid))) result)))) + ;; Very simple shell command wrapper that returns lines produced by + ;; given command. + (define (get-process-exit+output-lines cmd . args) + (let-values (((stdout stdin pid stderr) + (process* cmd + (map (lambda (x) + (format "~A" x)) + args)))) + (close-output-port stdin) + (let ((result (read-lines stdout))) + (let-values (((pid exit-ok? exit/signal) (process-wait pid))) + (values exit/signal result))))) + ;; Invokes given command with given arguments, gives it all input ;; lines and returns the output lines. (define (process-send/recv cmd args . lines)