I'm using call-process in an emacs/lisp file (in Spacemacs) to run an external command and write its output to a file. It works when I hard code the path like this:
(call-process "/bin/ls" nil '(:file "/Users/alan/Desktop/tmp.txt"))
However, I can't get it to work when I use a variable for the path.
When I do:
(defvar path-to-output-test nil
"Path to send the file to")
(setq path-to-output-test
"/Users/alan/Desktop/tmp-4.txt"
)
(call-process "/bin/ls" nil '(:file path-to-output-test))
I get:
setq: Wrong type argument: stringp, path-to-output-test
I tried setting the variable directly with:
(defvar path-to-output-test
"/Users/alan/Desktop/tmp-4.txt"
"Path to send the file to")
And by adding a concat
with:
(setq path-to-output-test
(concat "/Users/alan/Desktop/tmp-5.txt" )
)
I also tried a bunch of other combinations:
(call-process "/bin/ls" nil '(:file path-to-output-test))
(call-process "/bin/ls" nil '(:file 'path-to-output-test))
(call-process "/bin/ls" nil '(:file `path-to-output-test))
(call-process "/bin/ls" nil '((:file path-to-output-test)))
(call-process "/bin/ls" nil '((:file 'path-to-output-test)))
(call-process "/bin/ls" nil '((:file `path-to-output-test)))
(call-process "/bin/ls" nil '('(:file path-to-output-test)))
(call-process "/bin/ls" nil '('(:file 'path-to-output-test)))
(call-process "/bin/ls" nil '('(:file `path-to-output-test)))
(call-process "/bin/ls" nil '(stringp (:file 'path-to-output-test)))
(call-process "/bin/ls" nil '(stringp '(:file 'path-to-output-test)))
(call-process "/bin/ls" nil '(stringp `(:file 'path-to-output-test)))
(call-process "/bin/ls" nil '(:file (string path-to-output-test)))
(call-process "/bin/ls" nil '(:file '(string path-to-output-test)))
(call-process "/bin/ls" nil '(:file `(string path-to-output-test)))
(call-process "/bin/ls" nil '(:file (stringp path-to-output-test)))
(call-process "/bin/ls" nil '(:file '(stringp path-to-output-test)))
(call-process "/bin/ls" nil '(:file `(stringp path-to-output-test)))
(call-process "/bin/ls" nil '(:file (make-string path-to-output-test)))
(call-process "/bin/ls" nil '(:file '(make-string path-to-output-test)))
(call-process "/bin/ls" nil '(:file `(make-string path-to-output-test)))
(call-process "/bin/ls" nil '(:file (make-string 'path-to-output-test)))
(call-process "/bin/ls" nil '(:file '(make-string 'path-to-output-test)))
(call-process "/bin/ls" nil '(:file `(make-string 'path-to-output-test)))
(call-process "/bin/ls" nil '(:file (prin1 path-to-output-test)))
(call-process "/bin/ls" nil '(:file '(prin1 path-to-output-test)))
(call-process "/bin/ls" nil '(:file `(prin1 path-to-output-test)))
(call-process "/bin/ls" nil '(:file (concat path-to-output-test)))
(call-process "/bin/ls" nil '(:file '(concat path-to-output-test)))
(call-process "/bin/ls" nil '(:file `(concat path-to-output-test)))
(call-process "/bin/ls" nil `(:file path-to-output-test))
(call-process "/bin/ls" nil `(:file 'path-to-output-test))
(call-process "/bin/ls" nil `(:file `path-to-output-test))
None of those worked. They all returned a similar error but with whatever code I was trying to use for the iteration.
These tries didn't throw an error, but they didn't output the file:
(call-process "/bin/ls" nil (stringp '(:file path-to-output-test)))
(call-process "/bin/ls" nil (stringp '(:file 'path-to-output-test)))
(call-process "/bin/ls" nil (stringp '(:file `path-to-output-test)))
I'm new to emacs/lisp and am out of ideas at this point.