Created
April 16, 2019 16:29
-
-
Save invkrh/0cc824a7973e94e1c64b3b992c220acc to your computer and use it in GitHub Desktop.
Implement spark.rdd.pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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