如何在 elisp 中捕获 shell 命令的标准输出?
我想在 Emacs 中运行 shell 命令并将完整输出捕获到变量中。有办法做到这一点吗?例如,我希望能够通过以下方式将 hello-string
设置为 "hello"
:
(setq hello-string (capture-stdout-of-shell-command "/bin/echo hello"))
函数 capture-stdout-of-shell -command
存在,如果存在,它的真实名称是什么?
I want to run a shell command within Emacs and capture the full output to a variable. Is there a way to do this? For example, I would like to be able to set hello-string
to "hello"
in the following manner:
(setq hello-string (capture-stdout-of-shell-command "/bin/echo hello"))
Does the function capture-stdout-of-shell-command
exist, and if so what is its real name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
shell-command- to-string
满足您的目的吗?例如:
Does
shell-command-to-string
meet your purpose?For example:
我有一个建议可以扩展伊势紫藤的答案。尝试使用类似这样的内容:
这应该将字符串“hello”设置为 my_shell_output 的值,但要干净。使用
(substring)
可以消除 emacs 调用 shell 命令时经常出现的尾随\n
。它让我在 Windows 上运行的 emacs 中感到困扰,并且可能也会在其他平台上发生。I have a suggestion to made that extends Ise Wisteria's answer. Try using something like this:
This should set the string
"hello"
as the value ofmy_shell_output
, but cleanly. Using(substring)
eliminates the trailing\n
that tends to occur when emacs calls out to a shell command. It bothers me in emacs running on Windows, and probably occurs on other platforms as well.最后,“git log”“--reverse”选项派上了用场)。使用最初始提交时的当前缓冲区文件打开缓冲区。
而关于这个问题
Finally, the "git log" "--reverse" option came in handy ). Open a buffer with the current buffer file as of the most initial commit.
And on the question of