GNU bug report logs - #74550
eshell cannot set the environment variable PATH on Windows

Previous Next

Package: emacs;

Reported by: Siyuan Chen <chansey97 <at> gmail.com>

Date: Tue, 26 Nov 2024 20:39:01 UTC

Severity: normal

To reply to this bug, email your comments to 74550 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#74550; Package emacs. (Tue, 26 Nov 2024 20:39:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Siyuan Chen <chansey97 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 26 Nov 2024 20:39:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Siyuan Chen <chansey97 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: eshell cannot set the environment variable PATH on Windows
Date: Wed, 27 Nov 2024 04:38:30 +0800
[Message part 1 (text/plain, inline)]
Reproduce steps:

1. Emacs -Q

2. M-x eval-expression `(setenv "PATH" (concat "C:/env" path-separator
(getenv "PATH")))`

3. M-x eshell

4. In the *eshell* window, type `echo $PATH`, but the path "C:/env" doesn't
show in the result.

P.S. I have also tried `eshell-set-path` and `with-environment-variables`,
but they cannot set PATH as well. For example,

(require 'eshell)

(defun eshell2()
  (interactive)
  (eshell-set-path '("C:/env"))
  (call-interactively 'eshell))

(defun eshell3()
  (interactive)
  (with-environment-variables (("PATH" (concat "C:/env" path-separator
(getenv "PATH"))))
    (call-interactively 'eshell)))

Emacs 29.4 on Windows 10.

Thanks.

Best regards,
Siyuan Chen
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74550; Package emacs. (Tue, 26 Nov 2024 21:16:02 GMT) Full text and rfc822 format available.

Message #8 received at 74550 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Siyuan Chen <chansey97 <at> gmail.com>, 74550 <at> debbugs.gnu.org
Subject: Re: bug#74550: eshell cannot set the environment variable PATH on
 Windows
Date: Tue, 26 Nov 2024 13:14:42 -0800
On 11/26/2024 12:38 PM, Siyuan Chen wrote:
> Reproduce steps:
> 
> 1. Emacs -Q
> 
> 2. M-x eval-expression `(setenv "PATH" (concat "C:/env" path-separator 
> (getenv "PATH")))`
> 
> 3. M-x eshell
> 
> 4. In the *eshell* window, type `echo $PATH`, but the path "C:/env" 
> doesn't show in the result.

Thanks for the bug report. This is an intentionally-incompatible change 
in Eshell to improve behavior with remote systems via Tramp. Here's the 
relevant section from the Emacs 29 NEWS:

> *** Eshell's PATH is now derived from 'exec-path'.
> For consistency with remote connections, Eshell now uses 'exec-path'
> to determine the execution path on the local or remote system, instead
> of using the PATH environment variable directly.

So instead, you want to do something like '(push "C:/env" exec-path)' in 
order to update the PATH in a way where Eshell sees it.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74550; Package emacs. (Wed, 27 Nov 2024 17:17:02 GMT) Full text and rfc822 format available.

Message #11 received at 74550 <at> debbugs.gnu.org (full text, mbox):

From: Siyuan Chen <chansey97 <at> gmail.com>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 74550 <at> debbugs.gnu.org
Subject: Re: bug#74550: eshell cannot set the environment variable PATH on
 Windows
Date: Thu, 28 Nov 2024 01:15:34 +0800
[Message part 1 (text/plain, inline)]
Dear Jim,

It works, thanks.

However, this seems to be a global setting only. Is there any equivalent of
with-environment-variables for exec-path?

For example, with regular shell, I can do something like:

```
(defun shell1 ()
  (interactive)
  (let ((explicit-shell-file-name "cmdproxy")
        (current-prefix-arg 4))
    (with-environment-variables (("PATH" (concat "C:/env1" path-separator
(getenv "PATH"))))
      (call-interactively 'shell))
    ))

(defun shell2 ()
  (interactive)
  (let ((explicit-shell-file-name "cmdproxy")
        (current-prefix-arg 4))
    (with-environment-variables (("PATH" (concat "C:/env2" path-separator
(getenv "PATH"))))
      (call-interactively 'shell))
    ))
```

to create two *shell* buffers with different PATH "C:/env1" and "C:/env2".

How to do the same thing in eshell?

I have tried with the following code but it doesn't work as expected.

 ```
 (defun eshell1()
  (interactive)
  (let ((exec-path (cons "C:/env1" (copy-sequence exec-path)))
        (current-prefix-arg "new"))
    (call-interactively 'eshell)))
 ```

 ```
 (defun eshell2()
  (interactive)
  (let ((exec-path (cons "C:/env2" (copy-sequence exec-path)))
        (current-prefix-arg "new"))
    (call-interactively 'eshell)))
 ```

M-x eshell1 and echo $PATH

M-x eshell2 and echo $PATH

The result is that the eshell1 buffer can show C:/env1, but eshell2 can not.

Thanks.

Best regards,
Siyuan Chen

On Wed, Nov 27, 2024 at 5:14 AM Jim Porter <jporterbugs <at> gmail.com> wrote:

> On 11/26/2024 12:38 PM, Siyuan Chen wrote:
> > Reproduce steps:
> >
> > 1. Emacs -Q
> >
> > 2. M-x eval-expression `(setenv "PATH" (concat "C:/env" path-separator
> > (getenv "PATH")))`
> >
> > 3. M-x eshell
> >
> > 4. In the *eshell* window, type `echo $PATH`, but the path "C:/env"
> > doesn't show in the result.
>
> Thanks for the bug report. This is an intentionally-incompatible change
> in Eshell to improve behavior with remote systems via Tramp. Here's the
> relevant section from the Emacs 29 NEWS:
>
> > *** Eshell's PATH is now derived from 'exec-path'.
> > For consistency with remote connections, Eshell now uses 'exec-path'
> > to determine the execution path on the local or remote system, instead
> > of using the PATH environment variable directly.
>
> So instead, you want to do something like '(push "C:/env" exec-path)' in
> order to update the PATH in a way where Eshell sees it.
>
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74550; Package emacs. (Wed, 27 Nov 2024 18:54:02 GMT) Full text and rfc822 format available.

Message #14 received at 74550 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Siyuan Chen <chansey97 <at> gmail.com>
Cc: 74550 <at> debbugs.gnu.org
Subject: Re: bug#74550: eshell cannot set the environment variable PATH on
 Windows
Date: Wed, 27 Nov 2024 10:52:47 -0800
On 11/27/2024 9:15 AM, Siyuan Chen wrote:
> It works, thanks.
> 
> However, this seems to be a global setting only. Is there any equivalent 
> of with-environment-variables for exec-path?

Not exactly. However, you can use setq-local or eshell/addpath:

  (defun shell1 ()
    (interactive)
    (let ((current-prefix-arg 4))
      (call-interactively 'shell)
      (setq-local exec-path (cons "C:/foo" exec-path))
      ;; or ...
      (eshell/addpath "-b" "C:/foo")))

That's probably the best way to do it for now. I think it's probably 
reasonable for Eshell to work correctly when you've let-bound 
'exec-path' like in your examples, but I'll have to think about the best 
way to do it.




This bug report was last modified 205 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.