通常,如果要在编译完成后运行某些内容,请将其添加到编译命令中.例如,而不是
M-x compile RET make RET
Run Code Online (Sandbox Code Playgroud)
你可以输入
M-x compile RET make && ./test RET
Run Code Online (Sandbox Code Playgroud)
或者您可以将程序添加到makefile中的某个适当的目标,这样就可以了
M-x compile RET make test RET
Run Code Online (Sandbox Code Playgroud)
也许如果您能解释为什么要在eshell中运行已编译的程序,我可以为您提供更好的建议.
但是,如果您坚持使用eshell,则可以使用compilation-finish-functions:
编译过程完成时调用的函数.每个函数都使用两个参数调用:编译缓冲区和描述进程如何完成的字符串.
这不是所有文档都记录"finished\n"完毕,但字符串是过程成功完成的.所以你可能会这样做:
(defun run-compilation-output-in-eshell (buf msg)
"If compilation finished successfully, switch to eshell and execute a command."
(when (string= msg "finished\n")
(eshell)
(goto-char (point-max))
(eshell-kill-input)
(insert "echo command goes here")
(eshell-send-input)))
(add-hook 'compilation-finish-functions #'run-compilation-output-in-eshell)
Run Code Online (Sandbox Code Playgroud)
但这似乎相当粗鲁:如果您eshell在编译完成时碰巧输入缓冲区,那么这将删除您的输入.正如我上面所说,更多的上下文可能会有所帮助.