【问题标题】:How do I create a pipe between two processes in Guile?如何在 Guile 中的两个进程之间创建管道?
【发布时间】:2013-08-28 12:30:11
【问题描述】:

我想在 Guile 中创建两个进程,并将其中一个的输出(stdout)作为输入(stdin)发送到另一个。

使用下面的例子,如何做到这一点?

echo "foo bar" | wc

输出:

1       2       8

【问题讨论】:

    标签: process scheme pipe guile


    【解决方案1】:

    是的,您可以使用open-output-pipe

    (let ((p (open-output-pipe "wc")))
      (display "The quick brown fox jumps over the lazy dog.\n" p)
      (close-pipe p))
    

    这相当于echo "The quick brown fox jumps over the the lazy dog." | wc(包括echo 的隐式换行符,因为我就是这么特别,哈哈)。

    当然,有一个open-input-pipe 类似物。阅读 Guile 手册的Pipes 部分了解更多详细信息。

    【讨论】:

    • 这不能回答问题,并且在您引用的手册页上也没有任何接近它的示例。
    • @Daniel 相当于echo "The quick brown fox jumps over the lazy dog." | wc
    • 抱歉,我明白了!谢谢!
    • @Daniel 我通常不会在没有实质性改变的情况下编辑帖子,但在这种情况下,我认为添加一点解释并没有什么坏处。 ;-)
    • 是否可以将示例扩展到 generate some data | grep something in it | sed something more 类型的命令,而不是使用多个管道。 Guile 的 posix 命令以不同/意想不到的方式接受参数,很难找到有用/全面的文档和示例
    猜你喜欢
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 2011-05-17
    • 2011-07-11
    • 2011-06-18
    相关资源
    最近更新 更多