Emacs Lisp irregular subprocesses with custom environment variables

Basically I want to create a process that changes its working directory. My idea was to create a process and set a PWD environment variable.

Is there a way to get something like this?

(in fact, I would like to change any of the environment variables for flexibility)

+3
source share
4 answers

Just bind the variable default-directoryuntil your process appears. Example:

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

I ran this from my buffer *scratch*, and the line working dir is /tmpwas added to the buffer.

+2
source

Do you mean this?

The default environment variables are displayed here:

(shell-command "env")

, :

(shell-command "PWD=/tmp env")
+2
+2

, python , (, , ), :

(let* ((default-directory (find-correct-dir))
       (process-environment (cons (format "PWD=%s" default-directory)
                                  process-environment)))
  (do-the-subprocess-thing))

Or if I want to throw away the rest of the environment:

(let* ((default-directory (find-correct-dir))
       (process-environment (list (format "PWD=%s" default-directory))))
  (do-the-subprocess-thing))

That is, I had to set both default-directory, and process-environment, and to the same value.

+2
source

Source: https://habr.com/ru/post/1748395/


All Articles