【问题标题】:Named Pipes in ScalaScala 中的命名管道
【发布时间】:2015-08-06 01:48:24
【问题描述】:

我想使用命名管道在 Scala 和 Python 之间进行连接。但是,我无法在 Scala 中找到命名管道的示例。我的 Python 程序生成数据并将数据发送到 C++ 程序或 Scala 程序。我能够让命名管道连接在 Python 和 C++ 之间工作,但不能在 Python 和 Scala 之间工作。数据生产者是 Python 文件,而 C++ 或 Scala 是消费者。一世 我的操作系统是 Ubuntu 14.04。 如果有人可以在 scala 中发布命名管道的示例,那就太好了。 在此先感谢

【问题讨论】:

  • 核心 Scala 库不怎么处理文件 IO - 您可能应该只搜索如何在 Java 中执行此操作。

标签: scala pipe named-pipes


【解决方案1】:

这是一个以 Scala 为中心的方法,只是为了让事情开始。

// first mkfifo /tmp/NP

scala> import scala.io.Source
import scala.io.Source

// this will block until the pipe is written to
scala> val itr = Source.fromFile("/tmp/NP")
itr: scala.io.BufferedSource = non-empty iterator

// after I write "12345 to the end" to the pipe I can work with the iterator

scala> itr.descr
res9: String = file:/tmp/NP

scala> itr.hasNext
res10: Boolean = true

scala> itr.next
res11: Char = 1

scala> itr.next
res12: Char = 2

scala> itr.mkString
res13: String =
"345 to the end
"

等等

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多