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?

1
  • I found that (defvar standard-error 'external-debugging-output) makes the above behave nicely, thanks to @wasamasa Commented Jan 18, 2017 at 19:10

1 Answer 1

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 ;)

2
  • How did you find that out? Commented Jun 12, 2016 at 15:47
  • 1
    I jumped to the sources of princ with find-function, then searched the sources for usage of stderr. Eventually I found that special char printing function...
    – wasamasa
    Commented Jun 12, 2016 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.