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.

2 Answers 2

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/"))
  ...)
2
  • Works on linux without a slash
    – abo-abo
    Commented Dec 25, 2014 at 22:11
  • I'm on OSX, so in my case it made the difference -- i.e., expand-file-name is no longer needed.
    – lawlist
    Commented Dec 25, 2014 at 22:18
4

Just expand the file name:

(let ((default-directory "/Users/HOME/Desktop/tmp"))
  (start-process "touch-file" nil "touch"
                 (expand-file-name "test.txt")))
1
  • 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
    Commented Dec 25, 2014 at 22:18

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.