You can simply use let
to bind streams to output string streams. For example:
(defun print-stuff (x y)
(format t "standard output ~a" x)
(format *error-output* "error output ~a" y)
(+ x y))
(defun capture (x y)
(let ((*standard-output* (make-string-output-stream))
(*error-output* (make-string-output-stream)))
(values (print-stuff x y)
(get-output-stream-string *standard-output*)
(get-output-stream-string *error-output*))))
(capture 43 12)
; => 55
; "standard output 43"
; "error output 12"