preview-gs-command contains the following code:
(or ;; The GS wrapper coming with TeX Live
(executable-find "rungs")
;; The MikTeX builtin GS
(let ((gs (executable-find "mgs")))
;; Check if mgs is functional for external non-MikTeX apps.
;; See
http://blog.miktex.org/post/2005/04/07/Starting-mgsexe-at-the-DOS-Prompt.aspx
(when (= 0 (shell-command (concat gs " -q -dNODISPLAY -c quit")))
gs))
Even if the mgs executable is not found, the test is run, which results in a hard-to-diagnose "bash: -q: no such command" error, or similar.
Wrapping the test in (when gs ...) fixes this problem, i.e.:
(or ;; The GS wrapper coming with TeX Live
(executable-find "rungs")
;; The MikTeX builtin GS
(let ((gs (executable-find "mgs")))
(when gs
;; Check if mgs is functional for external non-MikTeX apps.
;; See
http://blog.miktex.org/post/2005/04/07/Starting-mgsexe-at-the-DOS-Prompt.aspx
(when (= 0 (shell-command (concat gs " -q -dNODISPLAY -c quit")))
gs)))
Checked against current git.