Move get-process-output-lines to util-io.

This commit is contained in:
Dominik Pantůček 2023-04-08 20:56:22 +02:00
parent 4ac7fdbc6d
commit 64cd360c0d
5 changed files with 29 additions and 19 deletions

View file

@ -29,10 +29,13 @@
util-io
(
read-lines/no-bom
get-process-output-lines
)
(import scheme
(chicken io))
(chicken base)
(chicken io)
(chicken process))
;; If given string begins with UTF-8 BOM, it is removed.
(define (remove-optional-bom str)
@ -52,4 +55,13 @@
(cons (remove-optional-bom (car lines))
(cdr lines)))))
;; Very simple shell command wrapper that returns lines produced by
;; given command. Dangerous - performs no argument escaping!
(define (get-process-output-lines cmd)
(let-values (((stdout stdin pid stderr) (process* cmd)))
(close-output-port stdin)
(let ((result (read-lines stdout)))
(let-values (((a b c) (process-wait pid)))
result))))
)