5
Emacs中如何在指定目录下运行shell命令
source link: https://www.lujun9972.win/blog/2018/09/19/emacs%E4%B8%AD%E5%A6%82%E4%BD%95%E5%9C%A8%E6%8C%87%E5%AE%9A%E7%9B%AE%E5%BD%95%E4%B8%8B%E8%BF%90%E8%A1%8Cshell%E5%91%BD%E4%BB%A4/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Emacs中如何在指定目录下运行shell命令
shell-command
与 shell-comand-to-string
可以用来在Emacs中运行shell命令,这两个函数都会自动根据shell命令是否以 &
结尾来自动同步/异步调度shell命令。
这两个命令的不同点在于:
shell-command
将shell命令的输出结果写入到新的buffer中shell-command-to-string
则将输出结果作为字符串返回
这两个命令内部都调用 call-process
,因此会将 default-directory
的值作为shell命令的工作目录(详细说明可以参见 call-process
的说明).
因此,Emacs中在指定目录下运行shell命令只需要在 let
中临时修改 default-directory
的值就行了,像这样
(let ((default-directory "/tmp")) (shell-command-to-string "pwd"))
/tmp
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK