3

I am using Emacs 29.3 on Windows 11.

I have included diff.exe in the PATH and the M-x diff command is working for me. However, when I try to run the M-x ediff command. I am presented with the ediff-exec-process: Searching for program: No such file or directory, diff error after entering the file A and file B paths.

The M-x getenv command shows the "C:\Program Files\Git\usr\bin" path in the PATH variable too.

I referred the discussions at the following places, but all of them mention adding diff.exe to the PATH solves the error, which is not the case for me,

The windows batch file I used to reproduce the error to ensure init.el is not messing things up,

set PATH="C:\Program Files\Git\usr\bin\";%PATH% D:\Programs\emacs-29.3\bin\emacs.exe -Q 
3
  • 2
    Check exec-path as well. That's what used for subprocesses. Commented Mar 10 at 17:05
  • 1
    I don't know anything about how Windows handles environment variables, but does that set PATH=... actually export the variable to the environment inherited by subsequent commands? In sh/bash one would need to export PATH explicitly. Under GNU/Linux Emacs initialises exec-path based on the inherited PATH, so either Windows is different (entirely possible), or else you're perhaps not testing what you thought you were testing? Commented Mar 11 at 6:55
  • 1
    Yes, SET command documentation says Changes made with SET will remain only for the duration of the current CMD session. I confirmed that Emacs inherits it. I will add more analysis in my answer. It is too difficult to mention everything in this comment. In short, the space in the directory name is spoiling things. Commented Mar 11 at 14:27

2 Answers 2

3

Check/compare:

  • C-hv ediff-diff-program
  • C-hv diff-command
3
  • Both values show value as diff. However, as mentioned by @NickD above the issue is with exec-path. Commented Mar 11 at 5:37
  • 2
    I'm really surprised that M-x diff was working as well if that's the case, but I'd need to look at code to see why that might be. Glad you got it sorted. Commented Mar 11 at 6:45
  • Your question is valid as exec-path is derived from PATH in the first place. I will add more analysis on what's happening in my answer below. Commented Mar 11 at 14:28
1

As mentioned by @NickD in the comments, adding the below line to my init.el solved the issue,

(add-to-list 'exec-path "C:/Program Files/Git/usr/bin/") 

I also had the following earlier (this allows M-x diff to work),

(setenv "PATH" (concat "C:/Program Files/Git/usr/bin/" path-separator (getenv "PATH"))) 

EDIT based on questions from @phils:

@phils raised a valid question that exec-path is derived from the PATH environment variable. So, I investigated this further,

When I put the following in the batch file,

set PATH="C:\Program Files\Git\usr\bin\";%PATH% D:\Programs\emacs-29.3\bin\emacs.exe -Q 

Both variables diff-command and ediff-diff-program showed the value as diff.

However, M-x diff worked but M-x ediff failed with ediff-exec-process: Searching for program: No such file or directory, diff error

The variable exec-path value showed the following (trimmed the additional directory paths),

("\"C:/Program Files/Git/usr/bin/\"" "C:/Program Files/Python312/Scripts/" "C:/Program Files/Python312/" "D:/Programs/jdk-11.0.2/bin"... 

Here you can see that the double quotes in the path are preserved.

The M-x getenv followed by PATH gave (trimmed later dir paths),

"C:\Program Files\Git\usr\bin\";C:\Program Files\Python312\Scripts\;C:\Program Files\Python312\;D:\Programs\jdk-11.0.2\bin;... 

When I used a directory name without spaces in the PATH things started working smoothly.

Here is the modified batch file,

set PATH=d:\Programs\cygwin64\bin;%PATH% D:\Programs\emacs-29.3\bin\emacs.exe -Q 

Now I got exec-path value as,

("d:/Programs/cygwin64/bin" "C:/Program Files/Python312/Scripts/" "C:/Program Files/Python312/" "D:/Programs/jdk-11.0.2/bin" ... 

The program M-x ediff too started working without issues.

Summary: If you have spaces in the directory name, you need to use the double quotes to set PATH properly. But this breaks the exec-path behavior in Windows.

EDIT2: Based on the link given in the comments, double quotes in the path are not necessary. So, M-x ediff should work with the below batch file.

set PATH=C:\Program Files\Git\usr\bin\;%PATH% D:\Programs\emacs-29.3\bin\emacs.exe -Q 
3
  • Are you sure about "You need to use the double quotes"? Some web searching suggests to me that set PATH=C:\Program Files\Git\usr\bin\;%PATH% would do the right thing. I'm guessing Windows doesn't do command line word splitting the way that Unix shells tend to do. Commented Mar 11 at 22:58
  • superuser.com/a/452357 seems like a good reference. Commented Mar 11 at 23:05
  • You are right @phils. Double quotes are not necessary. Though I kind of remember my experience with older versions of Windows that forced me to use double quotes. Will edit the answer above. Commented Mar 12 at 3:54

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.