bash 在 MS Windows 上使用 Emacs 的“Mx 术语”:错误产生子进程:无效参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20263012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
`M-x term' with Emacs on MS Windows: error Spawning child process: invalid argument
提问by fniessen
whenever I try to launch M-x term from my Windows distribution of GNU Emacs, I get the error:
每当我尝试从 GNU Emacs 的 Windows 发行版中启动 Mx 术语时,我都会收到错误消息:
apply: Spawning child process: invalid argument
after accepting the default program to run (either "bash.exe" or "zsh.exe", from Cygwin, and present in my Windows PATH environment variable).
在接受要运行的默认程序(“bash.exe”或“zsh.exe”,来自 Cygwin,并存在于我的 Windows PATH 环境变量中)之后。
M-x shell does work with Zsh/Bash from Cygwin. But I'd like to use Term to get more features...
Mx shell 可以与 Cygwin 的 Zsh/Bash 一起使用。但我想使用 Term 来获得更多功能......
Any help?
有什么帮助吗?
采纳答案by Alex Vorobiev
From my experience none of the terminal emulators in Emacs (term, ansi-term, multi-term) is supported under Windows. It looks like the main reason is all of them rely on low-level support for terminals (stty, etc) which is not provided by Windows. Trying to force Emacs to use, say, Cygwin bash by editing references to e.g. /bin/sh in term.el doesn't help either. It maywork in Cygwin Emacs but I haven't used it in a long time because native W32 Emacs is so much better (for me). Shell mode works fine with either Cygwin bash or Windows cmd (via cmdproxy which is part of Emacs install). You can have support for ANSI colors if you do
根据我的经验,Windows 不支持 Emacs 中的任何终端模拟器(术语、ansi 术语、多术语)。看起来主要原因是它们都依赖于 Windows 未提供的对终端(stty 等)的低级支持。试图通过编辑 term.el 中的 /bin/sh 等引用来强制 Emacs 使用 Cygwin bash 也无济于事。它可能在 Cygwin Emacs 中工作,但我很久没有使用它了,因为原生 W32 Emacs 好得多(对我来说)。Shell 模式适用于 Cygwin bash 或 Windows cmd(通过 cmdproxy,它是 Emacs 安装的一部分)。如果你这样做,你可以支持 ANSI 颜色
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
I tried eshell many times but ended up using the shell mode with bash because I tend to use pipes and redirections a lot. Are there any particular applications that you would like to use that require full-featured terminal support? I was missing top
at first but then I just started using M-x proced
.
我尝试了很多次 eshell,但最终还是使用了 bash 的 shell 模式,因为我经常使用管道和重定向。是否有任何需要全功能终端支持的特定应用程序?top
起初我失踪了,但后来我才开始使用M-x proced
.
UPDATE: term
, ansi-term
, and multi-term
dowork in Cygwin emacs.
更新:term
,ansi-term
和multi-term
做在Cygwin的emacs的工作。
回答by Neil Strickland
This is an attempt to record a more general answer about the message "Spawning child process: invalid argument", which emacs produces in various situations. I am using emacs 25.0.50.1 on Windows 7, but I have looked into this before with earlier versions and I do not think that anything relevant has changed. For some reason, this error does not start the debugger even if debug-on-error
is set. However, it seems that the error is always generated by the function start-process
in subr.el
(in the top lisp directory). You can therefore enter M-x debug-on-entry RET start-process RET
, and then do whatever it is that caused the error. Emacs will then show a backtrace buffer, the second line of which will show the arguments passed to start-process
. The last argument is supposed to be the name of an executable file. In all cases where I have seen the "Spawning child process: invalid argument" error, the executable file did not actually exist. You then need to work out where emacs got the filename from, and how to change it. You can get some clues from the rest of the backtrace buffer.
这是尝试记录关于 emacs 在各种情况下产生的消息“Spawning child process: invalid argument”的更一般的答案。我在 Windows 7 上使用 emacs 25.0.50.1,但我之前在早期版本中研究过这个,我认为没有任何相关的变化。出于某种原因,即使debug-on-error
设置了此错误也不会启动调试器。然而,似乎总是由功能所产生的误差start-process
在subr.el
(在顶部口齿不清目录)。因此M-x debug-on-entry RET start-process RET
,您可以输入,然后执行导致错误的任何操作。然后 Emacs 将显示一个回溯缓冲区,其中第二行将显示传递给的参数start-process
. 最后一个参数应该是可执行文件的名称。在我看到“生成子进程:无效参数”错误的所有情况下,可执行文件实际上并不存在。然后您需要弄清楚 emacs 从哪里获得文件名,以及如何更改它。您可以从回溯缓冲区的其余部分获得一些线索。
In the case of the M-x term
command, the executable file used is the first of the following things that has a non-nil value:
在M-x term
命令的情况下,使用的可执行文件是以下具有非 nil 值的第一个:
- The lisp variable
explicit-shell-file-name
(which you can customize after enteringC-h v RET explicit-shell-file-name RET
) - The environment variable
ESHELL
- The environment variable
SHELL
- The hardcoded value
/bin/sh
- lisp 变量
explicit-shell-file-name
(输入后可以自定义C-h v RET explicit-shell-file-name RET
) - 环境变量
ESHELL
- 环境变量
SHELL
- 硬编码值
/bin/sh
(You can see this by looking at the code in term.el
in the top lisp directory.)
(您可以通过查看term.el
顶级 lisp 目录中的代码来看到这一点。)
回答by FabPop
I tried to run M-x term
from a MingW64 emacs with an MSYS2 bash.exe and I got the same error as you got. It is possible to get a little bit further by changing term-exec-1
in term.el
to read:
我试图M-x term
从带有 MSYS2 bash.exe 的 MingW64 emacs运行,但我遇到了和你一样的错误。它可以通过改变进一步得到一点点term-exec-1
的term.el
阅读:
(apply 'start-process name buffer
(getenv "SHELL") "-c"
(format "stty -nl echo rows %d columns %d sane 2>/dev/null;\
if [ = .. ]; then shift; fi; exec \"$@\""
term-height term-width)
".."
command "-i" switches)))
You need to answer with the MSYS2 shell path which is something like /usr/bin/bash.exe
and then you get a terminal. The problem is that the terminal is messed up. The stty command doesn't work on it and the cr doesn't work.
Also, the cd
emacs function receives MSYS2 paths like /c/usr/share/emacs/
which are not valid. This function needs to be advised to transform those paths to Windows paths.
你需要用 MSYS2 shell 路径来回答,就像这样/usr/bin/bash.exe
,然后你会得到一个终端。问题是终端搞砸了。stty 命令对它不起作用,cr 也不起作用。此外,cd
emacs 函数会接收类似/c/usr/share/emacs/
无效的MSYS2 路径。需要建议此函数将这些路径转换为 Windows 路径。
回答by juanleon
Looking in the source code of term.el, I can see a hardcoded"/bin/sh" that is used to launch the program to run (the one that exists in your path). If you can create a copy of your your bash.exe in that exact location and name (I am not sure if Windows cygwin paths allow that), you might get lucky.
查看 term.el 的源代码,我可以看到一个硬编码的“/bin/sh”,用于启动要运行的程序(存在于您的路径中的那个)。如果您可以在该确切位置和名称中创建 bash.exe 的副本(我不确定 Windows cygwin 路径是否允许),您可能会很幸运。