You will need to use a different function if you want to control where the export output goes. org-html-export-to-html
uses the name of the Org mode file and saves it in the same directory with the same name, except that the suffix is changed to .html
from .org
(except if EXPORT_FILE_NAME
is used - see below).
Here is a function that you can use to write the output of the exporter to a different file:
(defun my/org-html-export-to-file (file)
(let ((output (org-export-as 'html)))
(with-temp-buffer
(insert output)
(write-file file))))
The function stores the output of the exporter as a string and then creates a temporary buffer where it inserts the string - it then saves the buffer to the file given as argument to the function.
Assuming that you have saved the function to a file, say ~/src/emacs/lisp/org-html-to-file.el
, then the command line invocation becomes:
emacs --batch ./notes.org \
--load "~/src/emacs/lisp/org-html-to-file.el" \
--eval '(my/org-html-export-to-file "~/dest/notes.html")'
If the destination directory does not exist already, you will be asked whether to create it, which probably defeats the purpose, so you should probably create it in advance.
Alternatively, you can add a keyword line like this to your file:
#+EXPORT_FILE_NAME: ~/dest/notes.html
See Export settings.
The command line is simpler, basically what you wrote in your question, but without the (futile) attempt to eval
a different destination or redirect the output:
emacs --batch /tmp/foo.org -f org-html-export-to-html
org-html-export-to-html
writes its output to./notes.html
: you don't get a choice. If you want to write to a different file, you will need to use a different function.