6

When I run M-x term on the Windows version of Emacs, I am prompted to run C:/Program Files/emacs/libexec/emacs/25.1/x86_64-w64-mingw32/cmdproxy.exe

New versions of Windows 10 have the Linux subsystem and its shell (which is installed at C:\Windows\System32\bash.exe ~).

Is it possible to use this executable as the shell in Emacs?

I tried just pasting that path into the Run Program: path but I get the: Spawning child process error.

Is it possible to use this shell instead on Windows Emacs?

  • Are you able to use the Windows bash subsystem independently from Emacs? I think that's the first step as there is some configuration required (I believe, may have changed in more recent Win10 versions). – glucas Nov 15 '17 at 16:04
  • Yes. Ubuntu, on Windows 10 runs as a separate program. In fact, I can't run it from within emacs – Startec Nov 16 '17 at 8:06
  • Related to stackoverflow.com/questions/42346758/… – jmlorenzi Aug 17 '18 at 9:44
4

In my .emacs I first define a function like so

(defun my-bash-on-windows-shell ()
  (let ((explicit-shell-file-name "C:/Windows/System32/bash.exe"))
    (shell)))

and I call at the bottom using:

(my-bash-on-windows-shell)

Note that Emacs shell mode does not handle the default colored prompt very well, however changing my PS1 to:

PS1='\u@\h:\w\$ '

in my ~/.bashrc gave me a nice readable prompt.

  • I like this answer. However, I have noticed that after I kill the shell running the instance of Bash with exit then Ctl-x-k I can't open Bash again. The shell is empty and any input is just echoed back to the screen. Do have you this issue? – Startec Apr 15 '18 at 23:22
  • I've not noticed this, although I did do something slightly different - "(global-set-key [f9] 'my-bash-on-windows-shell)". I can type "exit" and the bash shall and restart it via F9 whenever needed. – SomeoneElse Mar 4 at 17:35
  • One other caveat to get this working - on a 64-bit version of Windows 10, the 64-bit version of Emacs must be installed (if you're using the Chocolatey package manager then "choco install emacs" will work just fine). Some other emacs Windows builds out there are 32-bit, which won't allow this to work. – SomeoneElse Mar 7 at 18:01
1

I can get it to run M-x term using /windows/system32/bash.exe in Cygwin emacs-w32 (c: is my Cygwin root), but my issue is that the prompts are not displayed. Note that the environment looks almost exactly the same except extra directories /mnt/c/Windows/System32:/mnt/c/usr/local/bin:/mnt/c/bin:/mnt/c/lib/lapack in $PATH.

  • Does this answer the question? You don't really say how you "can get it to run...". Is the lack of prompts the only problem you see? A little more info/clarification could help. – Drew Dec 26 '17 at 21:42
  • Assuming that the question is about running bash.exe from the Windows version of emacs as opposed to a Cygwin version running on Windows, this doesn't seem to work - it just gives a "spawning child process invalid argument" error. – SomeoneElse Mar 4 at 17:38
0

Windows 10 is supposed to have Bash built into it. If you are using Windows 10, I am sure that it is possible. https://msdn.microsoft.com/en-us/commandline/wsl/install_guide . It seems that there is also this if you are using other versions of Windows. https://sourceforge.net/projects/win-bash/?source=navbar . I have never used either of these, because I only use Windows at work. Good luck.

  • If you have an older version of Windows (pre 10) and Cygwin installed, then you may be able to adapt Bas Bossink's answer to invoke Cygwin instead of the WSL Bash prompt. I suspect the "win-bash" route would be less supported going forwards. – SomeoneElse Mar 4 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.