Disable *COMPILE-VERBOSE* and *LOAD-VERBOSE* for --script

Scripts using COMPILE or LOAD, either directly or through third party systems,
pollute the standard output with messages unrelated to the script itself.

This is undesirable (to quote a comment in toplevel.lisp, "scripts don't need
to be stylish or fast, but silence is usually a desirable quality") and can
cause bugs when the output of a script is processed through a UNIX pipe by a
program expecting to get output and not verbose diagnostic messages.

Problem originally signaled by Hraban Luyat <hraban@0brg.net>.
This commit is contained in:
Nicolas Martyanoff 2023-11-24 22:39:13 +01:00 committed by Douglas Katzman
parent 3343f31d8f
commit 3b3998bc73
3 changed files with 16 additions and 1 deletions

View file

@ -338,6 +338,11 @@ broken pipe) on either standard input, standard output, or standard
error, the script silently exits with code 0. This allows e.g. safely error, the script silently exits with code 0. This allows e.g. safely
piping output from SBCL to @code{head -n1} or similar. piping output from SBCL to @code{head -n1} or similar.
Additionally, the option sets @code{*compile-verbose*} and
@code{*load-verbose*} to @code{nil} while loading the file to avoid
potentially verbose diagnostic messages printed on the standard
output.
@end table @end table
@node Initialization Files @node Initialization Files

View file

@ -381,7 +381,13 @@ any non-negative real number."
(*debug-io* (make-two-way-stream *stdin* *stderr*)) (*debug-io* (make-two-way-stream *stdin* *stderr*))
(*standard-input* *stdin*) (*standard-input* *stdin*)
(*standard-output* *stdout*) (*standard-output* *stdout*)
(*error-output* *stderr*)) (*error-output* *stderr*)
;; Compile/load messages from the language implementation
;; are not really what one would expect from a script. And
;; these messages are printed on stdout interfere when
;; scripts are used as part as a UNIX pipeline.
(*compile-verbose* nil)
(*load-verbose* nil))
(load stream :verbose nil :print nil))))) (load stream :verbose nil :print nil)))))
(handling-end-of-the-world (handling-end-of-the-world
(if (eq t script) (if (eq t script)

View file

@ -26,6 +26,10 @@ echo '(exit :code 7)' > $tmpscript
run_sbcl --script $tmpscript run_sbcl --script $tmpscript
check_status_maybe_lose "--script exit status from EXIT" $? 7 "(status good)" check_status_maybe_lose "--script exit status from EXIT" $? 7 "(status good)"
echo '(when (and (null *load-verbose*) (null *compile-verbose*)) (exit :code 7))' > $tmpscript
run_sbcl --script $tmpscript
check_status_maybe_lose "--script verbosity" $? 7 "(silent)"
echo '(error "oops")' > $tmpscript echo '(error "oops")' > $tmpscript
run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
check_status_maybe_lose "--script exit status from ERROR" $? 1 "(error implies 1)" check_status_maybe_lose "--script exit status from ERROR" $? 1 "(error implies 1)"