Scala 中的命名管道

Named Pipes in Scala

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

这是一个以 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
"

等等