Reputation: 19
I would like to use a Named pipe to connect between Scala and Python. However, I am not able to find examples of named pipes in Scala. My Python program generates data and sends the data to either a C++ program or a Scala program. I am able to get the named pipes connection working between Python and C++ but not between Python and Scala. The data producer is the Python file while either C++ or Scala is the consumer. I My OS is Ubuntu 14.04. It would be great if anyone could post examples of named-pipes in scala. Thanks in advance
Upvotes: 1
Views: 870
Reputation: 51271
Here's a Scala-centric approach just to get things started.
// 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
"
etc.
Upvotes: 1