6

Is it possible to set the default-directory temporarily (e.g., let-bound) when using start-process? If so, how please.

(let ((default-directory "/Users/HOME/Desktop/tmp"))
  (start-process "touch-file" nil "touch" "test.txt"))

start-process ignores a let-bound default-directory.

lawlist
  • 18,826
  • 5
  • 37
  • 118

2 Answers2

8

default-directory has to be a directory, not the filename of a directory. In other words it has to end with a slash. In some places it does not matter whether a directory path ends with a slash or not, here it does.

(let ((default-directory "/some/directory/"))
  ...)
tarsius
  • 25,298
  • 4
  • 69
  • 109
4

Just expand the file name:

(let ((default-directory "/Users/HOME/Desktop/tmp"))
  (start-process "touch-file" nil "touch"
                 (expand-file-name "test.txt")))
abo-abo
  • 13,943
  • 1
  • 29
  • 43
  • tarsius hit the nail on the head, so I had to move the checkmark -- sorry -- your help is always appreciated. A forward slash at the end of the `default-directory` eliminates the need for `expand-file-name` on an OSX machine. – lawlist Dec 25 '14 at 22:18