Skip to content

Instantly share code, notes, and snippets.

@invkrh
Created April 16, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invkrh/0cc824a7973e94e1c64b3b992c220acc to your computer and use it in GitHub Desktop.
Save invkrh/0cc824a7973e94e1c64b3b992c220acc to your computer and use it in GitHub Desktop.
Implement spark.rdd.pipe
import scala.io.Source
import java.io.PrintWriter
val command = "/tmp/cmd.sh"
val proc = Runtime.getRuntime.exec(Array(command))
new Thread("stderr reader for " + command) {
override def run() {
for(line <- Source.fromInputStream(proc.getErrorStream).getLines)
System.err.println(line)
}
}.start()
val lineList = List("hello","how","are","you")
new Thread("stdin writer for " + command) {
override def run() {
val out = new PrintWriter(proc.getOutputStream)
for(elem <- lineList)
out.println(elem)
out.close()
}
}.start()
val outputLines = Source.fromInputStream(proc.getInputStream).getLines
println("======> " + outputLines.toList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment