From 6e8edfe8ab7d1902bdfa54fe83d38a61a35a3f15 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 15 Sep 2022 15:26:49 -0500 Subject: Refactor: to listen on stdout and stderr, and pritn accordingly --- lib/running.lisp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'lib/running.lisp') diff --git a/lib/running.lisp b/lib/running.lisp index b3a0b52..e4f9d63 100644 --- a/lib/running.lisp +++ b/lib/running.lisp @@ -36,21 +36,36 @@ have passed or CHECK returns non-nil." &key shell-name await-output-p - (output-stream *standard-output*)) + (output-stream *standard-output*) + (error-stream *error-output*)) "run COMMAND, a string, in a fresh shell environment, initialized with SHELL-NAME. The output from the command read line by line and is printed to OUTPUT-STREAM. " (let ((shell - (uiop:launch-program shell-name :input :stream :output :stream))) - (let ((shell-input (uiop:process-info-input shell)) - (shell-output (uiop:process-info-output shell))) + (uiop:launch-program + shell-name + :input :stream + :output :stream + :error-output :stream))) + (let ((shell-input + (uiop:process-info-input shell)) + (shell-err + (uiop:process-info-error-output shell)) + (shell-output + (uiop:process-info-output shell))) (write-line command shell-input) (finish-output shell-input) (when (and await-output-p (plusp await-output-p)) (loop while (wait-until (:timeout await-output-p :poll-every 0.05) - (listen shell-output)) - do (princ (read-line shell-output) output-stream) - (terpri output-stream)))))) + (or + (listen shell-err) + (listen shell-output))) + when (listen shell-output) + do (princ (read-line shell-output) output-stream) + (terpri output-stream) + else + do (princ (read-line shell-err) error-stream) + (terpri error-stream)))))) -- cgit v1.2.3