diff options
author | Colin Okay <okay@toyful.space> | 2022-02-11 15:31:57 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-02-11 15:31:57 -0600 |
commit | eec2a595bfc0c5ef7c0b215e446dc7cc33b9fcb6 (patch) | |
tree | 49f195e3e841d2d5eff8b14237c3c6c8b3c2be56 | |
parent | b849afd06be6da866a31a0be74d90851c0258134 (diff) |
testing out different command running situations; added wait-until
-rw-r--r-- | src/main.lisp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main.lisp b/src/main.lisp index 8d7db60..c7a2421 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -4,6 +4,12 @@ (:use :cl)) (in-package :oneliners.cli) +;;; CLI OPTIONS + +;; (opts:define-opts +;; (:name )) + + ;;; UTILITIES (defun parent-process-name () @@ -14,19 +20,31 @@ (with-open-file (input ppidfile) (read-line input))))))) +(defmacro wait-until ((&key (timeout 1) (poll-every 0.01)) &body check) + "Run CHECK every POLL-EVERY seconds until either TIMEOUT seconds +have passed or CHECK returns non-nil." + (let ((clockvar (gensym)) + (var (gensym))) + `(loop + for ,clockvar from 0 by ,poll-every to ,timeout + for ,var = (progn ,@check) + when ,var + return ,var + do (sleep ,poll-every)))) + (defun run-with-shell (command &key (shell-name (parent-process-name)) - (await-output-p t) + (await-output-p 0.5) (output-stream *standard-output*)) (let ((shell (uiop:launch-program shell-name :input :stream :output :stream))) (write-line command (uiop:process-info-input shell)) (finish-output (uiop:process-info-input shell)) (when await-output-p - (loop until (listen (uiop:process-info-output shell))) + (wait-until (:timeout await-output-p) + (listen (uiop:process-alive-p shell))) (loop while (listen (uiop:process-info-output shell)) do (princ (read-line (uiop:process-info-output shell)) output-stream) (terpri output-stream))))) - |