Is there a way to open a file on emacs, execute a command and quit, quietly? I tried

emacs file --eval '(progn (cmd) (kill-emacs))' 

But if I execute this, emacs shows up briefly before quitting. Is there a better way?

2 Answers 2


Consider using the batch mode to run some commands on a file. It's described in (emacs) Initial Options.

  • Is there a way to make emacs load the int file in batch mode?
    – Tohiko
    Sep 12, 2017 at 16:16
  • You can just use the load function to do that, but keep in mind that it will make your scripts depend on your configuration, which might not be what you want to accomplish.
    – user12563
    Sep 12, 2017 at 16:43

If you wish to run emacs as an elisp interpreter, consider using the --script command line switch, like,

emacs --script my-script.el

One can use emacs as shebang,

#!emacs --script

See related page on EmacsWiki.

Also, Run Emacs Lisp Code in Shell.

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.