diff --git a/inferior-shell.asd b/inferior-shell.asd index 835e6d69b37d4c14d16a09e1f0300321d81cf11c..494a59d439b53b24082569ea2c4ab2c0a5fef514 100644 --- a/inferior-shell.asd +++ b/inferior-shell.asd @@ -12,8 +12,9 @@ (:file "macros" :depends-on ("pkgdcl")) (:file "host" :depends-on ("pkgdcl")) (:file "run" :depends-on ("process-spec" "macros")) + (:file "run-generic" :depends-on ("process-spec" "macros")) #+ (and sbcl sb-thread unix) - (:file "run-sbcl" :depends-on ("process-spec" "macros")))) + (:file "run-sbcl" :depends-on ("process-spec" "macros" "run-generic")))) (defmethod perform ((op test-op) (system (eql (find-system :inferior-shell)))) (asdf:load-system :inferior-shell-test) diff --git a/pkgdcl.lisp b/pkgdcl.lisp index b710fe11add9718bcbb574dbd285752ab06a054a..930124f3a77b93e3f8be33aaf45d44d6202bf240 100644 --- a/pkgdcl.lisp +++ b/pkgdcl.lisp @@ -11,5 +11,6 @@ #:print-process-spec #:parse-process-spec #:command-arguments #:command-redirections #:redirection #:file-redirection #:fd-redirection #:close-redirection - #:! #:- #:< #:> #:<> #:>! #:>> #:>>! #:<& #:>& #:>&! #:>>&! - #:>& #:>> #:>>& #:pipe #:or #:and #:progn #:fork)) + #:! #:- #:< #:> #:<> #:>! #:>> #:>>! #:<& #:>& #:>&! #:>>&! + #:>& #:>> #:>>& #:pipe #:or #:and #:progn #:fork + #:*force-shell*)) diff --git a/run.lisp b/run.lisp index ae78ac538766f5c2ab3138339fa904760af200e5..7329ba0bb66d92cc851bdd6ca46fd5cb4db0aa68 100644 --- a/run.lisp +++ b/run.lisp @@ -2,6 +2,8 @@ (in-package :inferior-shell) +(defvar *force-shell* nil) + (defun run-program/interactively (command &key ignore-error-status) ;; force-shell wait (let ((return-code @@ -29,9 +31,11 @@ (null (command-redirections spec))) (command-arguments spec) (print-process-spec spec)))) - (run-program/ command - :ignore-error-status ignore-error-status - :output output))) + (if (eq output 't) + (run-program/ command :ignore-error-status ignore-error-status) + (run-program/ command + :ignore-error-status ignore-error-status + :output output)))) (defun run-process-spec (spec &rest keys &key ignore-error-status output host) (declare (ignore ignore-error-status output)) @@ -44,7 +48,9 @@ (apply 'run-process-spec (parse-process-spec spec) keys)) (process-spec #+(and sbcl sb-thread unix) - (sbcl-run spec t output t) + (if (not *force-shell*) + (sbcl-run spec t output t) + (run-spec spec :ignore-error-status ignore-error-status :output output)) #-(and sbcl sb-thread unix) (run-spec spec :ignore-error-status ignore-error-status :output output)))) (string diff --git a/test.lisp b/test.lisp index aeb852cea1de73c4016b788d48e0f3e598484830..f31e339dae7bd98e306b67b5b32635103a1365d7 100644 --- a/test.lisp +++ b/test.lisp @@ -13,8 +13,20 @@ :in root-suite :documentation "Testing inferior-shell")) +(defmacro w-sh (&body body) + `(let ((*force-shell* t)) + ,@body)) + +(defmacro wo-sh (&body body) + `(let ((*force-shell* t)) + ,@body)) + (deftest test-inferior-shell () - (is (equal (run/ss "echo 1 2 3") "1 2 3")) - (is (equal (run/ss `(pipe (echo (+ hel "lo,") world) - (tr "hw" "HW") (sed -e "s/$/!/"))) + (is (equal (w-sh (run/ss "echo 1 2 3")) "1 2 3")) + (is (equal (wo-sh (run/ss "echo 1 2 3")) "1 2 3")) + (is (equal (w-sh (run/ss `(pipe (echo (+ hel "lo,") world) + (tr "hw" "HW") (sed -e "s/$/!/")))) + "Hello, World!")) + (is (equal (wo-sh (run/ss `(pipe (echo (+ hel "lo,") world) + (tr "hw" "HW") (sed -e "s/$/!/")))) "Hello, World!")))