3

In emacs --batch (also, emacs --script),

(message "My Message")

will print "My Message" to standard error (file descriptor 2) along with a trailing newline.

What if I don't want the newline? I see that theoretically,

(princ "My Message" standard-error)` 

would work, if standard-error were defined.

Confusingly, standard-output and standard-input are defined, however.

Is this even possible?

  • I found that `(defvar standard-error 'external-debugging-output)` makes the above behave nicely, thanks to @wasamasa – Joel M Ward Jan 18 '17 at 19:10

1 Answers1

5

According to the manual, anything printing a message in batch mode will use stderr for this. The print/prin1/princ family will continue printing to stdout unless you pass the optional argument for picking a different char printing function, therefore the following will work:

(princ "My Message" 'external-debugging-output)

Apparently the Emacs developers consider stderr only for reporting errors and debug output ;)

wasamasa
  • 21,803
  • 1
  • 65
  • 97