views:

83

answers:

3

Basically I want to spawn a process changing its working directory. My idea was to spawn a process and set the PWD enviroment variable.

There's a way to obtain something like that?

(virtually I would like to change any of the environment variables for flexibility)

+1  A: 

Do you mean like this?

This shows the default environment variables:

(shell-command "env")

and this shows how you could change them on a per-process basis:

(shell-command "PWD=/tmp env")
unutbu
+1  A: 

Just bind the default-directory variable before spawning your process. Example:

(let ((default-directory "/tmp/"))
  (call-process "/bin/bash" nil "*scratch*" nil "-c" "echo working dir is $PWD"))

I ran this from my *scratch* buffer and the string working dir is /tmp was added to the buffer.

Sean
+1  A: 

$PWD is an environment variable that reflects the current working directory, not one that controls it.

According to the Processes section of the Elisp manual, the default directory for a spawned process is determined by the value of default-directory. The environment of the spawned process is the same as that of the Emacs session, which you can modify with setenv. You can also specify environment variables which are used solely for spawned processes via the process-environment variable.

jamessan