首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将输出从一个外部进程输送到另一个进程?

如何将输出从一个外部进程输送到另一个进程?
EN

Stack Overflow用户
提问于 2015-05-27 08:52:47
回答 1查看 272关注 0票数 1

我编写了一个函数,它接受所选区域的内容,然后通过两个外部进程运行它。实际上,我想复制的行为是M-| smartypants -2 | ascii2uni -a D -q

下面的函数可以工作,但需要对call-process-region进行两次调用,并将第一个进程的输出暂时存储在缓冲区中。有更好的方法吗?

代码语言:javascript
复制
(defun convert-ascii-to-unicode (&optional b e)
  "Converts ascii punctuation marks (quotes, dashes, and ellipses) into their unicode equivilents."
  (interactive "r")
  (let ((output-buffer (generate-new-buffer "*ASCII to Unicode Output*")))
    (call-process-region b e "smartypants" nil output-buffer nil "-2")
    (set-buffer output-buffer)
    (call-process-region (point-min) (point-max) "ascii2uni" t output-buffer nil "-a" "D" "-q")
    (switch-to-buffer-other-window output-buffer)))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-27 15:38:22

只需在shell命令中使用管道,下面的命令就可以执行您想要的操作:

代码语言:javascript
复制
(defun convert-ascii-to-unicode (beg end)
  (interactive "r")
  (shell-command
   (format "smartypants -2 %s | ascii2uni -a D -q"
           (shell-quote-argument (buffer-substring beg end)))))

切换到*Shell Command Output*以查看输出。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30477567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档